Log in

View Full Version : Solved: Finding Records



JustJerry
10-05-2005, 03:55 PM
I have the following code on another database that I am trying to incorporate into a new database. This code works fine as long as 'ID' is a "Number" data type.

Private Sub Combo214_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " & Str(Nz(Me![Combo214], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

However, in the new database, 'ID' is a text value and I tried changing the code, with no luck, to work as follows:

Private Sub Combo12_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ID] = " Me![Combo12]
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

When running the above code, I get a 'type mismatch' error.

Thanks in advance for any help

Jerry

TheAntiGates
10-05-2005, 06:25 PM
I don't know why you removed Str(), though I use CStr() anyway. Anyway, every combobox that I've used has been text, so that may be moot - I'm not sure.

Try debug.print "<" & Me![Combo12] & ">" to see just what's there, for one thing.

Did you paste the exact code? There's no ampersand in the "revised" code.

JustJerry
10-05-2005, 07:34 PM
Sorry, ok, I changed my code to CStr, and this is what I have now.

Private Sub Combo12_AfterUpdate()
'Find Matching Antenna Record
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[AntTypeID] = " & CStr(Me![Combo12])
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

It is telling me now that I get a runtime error 3077.
Syntax error (missing operator) in expression.

The CStr(Me![Combo12]) shows the value in the combobox I am selecting, for example "PL10-59A".

geekgirlau
10-05-2005, 08:06 PM
You need quotation marks around the text value

rs.FindFirst "[AntTypeID] = " & Chr(34) & CStr(Me![Combo12]) & Chr(34)

JustJerry
10-05-2005, 08:13 PM
Thank you, and yes, you beat me to the punch again. I had realized what it was I was doing wrong, and this is what I ended up that finally worked.

Thanks again everyone~

Private Sub Combo15_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[AntTypeID] = '" & Me![Combo15] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

TheAntiGates
10-05-2005, 08:13 PM
You might want quotes on that statement...
rs.FindFirst "[AntTypeID] = '" & CStr(Me![Combo12]) & "'"
or
rs.FindFirst "[AntTypeID] = " & """ & CStr(Me![Combo12]) & """
(for this, check that I expressed the """ correctly)

The CStr or Str do seem redundant for you, though harmless.

JustJerry
10-05-2005, 08:15 PM
It's great you all are so ready to help. I learn lots by coming here:friends: