SteveL13
asked on
Navigate to a record using a combo box
I have a form which contains a combo box. When the user selects a record from the combo box I want that record to be displayed on the form. But I'm getting a type mismatch error. Here's the code.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[PartN] = " & Str(Nz(Me![Combo34], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
PartN is a text field by the way. What is wrong with the code?
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[PartN] = " & Str(Nz(Me![Combo34], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
PartN is a text field by the way. What is wrong with the code?
Chr(34) are double quotes.
Single quotes also work:
Set rs = Me.Recordset.Clone
rs.FindFirst "[PartN] = '" & Str(Nz(Me![Combo34], 0)) & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
But they will cause errors if your data contains single quotes ('), such as in names like O'Brien.
Single quotes also work:
Set rs = Me.Recordset.Clone
rs.FindFirst "[PartN] = '" & Str(Nz(Me![Combo34], 0)) & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
But they will cause errors if your data contains single quotes ('), such as in names like O'Brien.
And I would recommend using the rs.nomatch method to determine whether there was a match.
Set rs = me.recordsetclone
Rs.findfirst "[PartN] = '" & nz(me.combo34,0) & """"
If rs.nomatch = false then me.bookmark = rs.bookmark
Set rs = me.recordsetclone
Rs.findfirst "[PartN] = '" & nz(me.combo34,0) & """"
If rs.nomatch = false then me.bookmark = rs.bookmark
ASKER
When I copy/paste this code I get red copy on the 2nd line...
Set rs = Me.Recordset.Clone
rs.FindFirst "[PartN] = " & chr(34) & & Str(Nz(Me![Combo34], 0)) & chr(34)
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Set rs = Me.Recordset.Clone
rs.FindFirst "[PartN] = " & chr(34) & & Str(Nz(Me![Combo34], 0)) & chr(34)
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
ASKER
Sorry.. I meant type mismatch
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That did it. Thanks.
Set rs = Me.Recordset.Clone
rs.FindFirst "[PartN] = " & chr(34) & & Str(Nz(Me![Combo34], 0)) & chr(34)
If Not rs.EOF Then Me.Bookmark = rs.Bookmark