"Find" List Box won't Find!

Dugantrain

I Love Pants
Local time
Today, 18:18
Joined
Mar 28, 2002
Messages
221
I have a list box which is bound to a table. Column Count is 3, first column is a bound, invisible Autonum field. I have this code in order to find a record from the form's recordset.

Code:
Private Sub List_Inst_ID_DblClick(Cancel As Integer)
Dim rs As Object
Set rs = Me.RecordsetClone
rs.findfirst "[install_id]='" & me![list_Inst_ID] & "'"
Me.Bookmark = rs.Bookmark
End Sub

Every time I double-click, however, I get the "Data Type Mismatch" error. I thought that maybe the list box was reading its autonum as text, so I tried to force the issue by using:

Code:
Private Sub List_Inst_ID_DblClick(Cancel As Integer)
Dim lstval As Long
lstval = Val(Me.List_Inst_ID)
Dim rs As Object
Set rs = Me.RecordsetClone
rs.findfirst "[install_id]='" & lstval & "'"
Me.Bookmark = rs.Bookmark
End Sub

Still a mismatch. What's going on here?
 
Last edited:
Looks like you're doing a match on the autonumber field from the Me.List_Inst_ID listbox to the install_id field of your recordset (and I assume you've defined and opened the original recordset that you're cloning somewhere else).

Aren't autonumber fields usually, well, numbers? Basically a type of long integer? Why are you doing a text-type comparison using the ' characters as in: rs.findfirst "[install_id]='" & me![list_Inst_ID] & "'"
 
first code example

rs.findfirst "[install_id]= " & me![list_Inst_ID]
 
Oh, Jeez, that's all it is; just the use of the quotes. Sorry guys, thanks for the fast help (SQL's playing catch up to the rest of my VBA and I guess my brain forgot to make a Reference to single quotes).
 
Last edited:

Users who are viewing this thread

Back
Top Bottom