Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recordset: Findfirst is finding the wrong record

Status
Not open for further replies.

jmgibson

Technical User
Oct 1, 2002
81
US
Hi everyone,

I've placed a combo box on a form and asked Access to Find a record based on the selection within the form. Since I leveraged the Access Wizard to do this when adding the combo box, it drops in the following code.

Private Sub Combo31_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[empNum] = " & Str(Me![Combo31])
Me.Bookmark = rs.Bookmark
End Sub

When I select the value in the combobox (emp id# 123456), the form returns the first CLOSEST match (emp id# 1234). Is there a way to have access return the exact match instead of the first closest match it finds?
 
The reason is you convert it to a string and then treat it like a numeric. Which is it?

rs.findfirst "empNum = '" & str(me.combo31) & "'"
or
rs.findfirst "empNum = " me.combo31

you can not have it both ways.
 
Hopefully empNum is a string in your table; since you should really only have numerics for values u need to calc. At least that was the rule many many moons ago.

Steve Medvid
IT Consultant & Web Master

Chester County, PA Residents
Please Show Your Support...
 
Try taking out the Str function - that adds a space in front of it.

smedvid - I can't think of a good reason why you wouldn't use a number if the value actually is a number, whether you need to calculate it or not.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top