Searching a text field?..Confused with my code!!

JustMaybe

Registered User.
Local time
Today, 18:39
Joined
Oct 18, 2002
Messages
134
Hi I have a problem, that’s been getting to me for ages. I’m trying to code a combo box to be a search field. I have used the following code successfully over loads of forms….where I’m searching for a primary key (which is a number)

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

However I really need to search for a text field..is the above only for number fields or primary keys???...am really confused…any enlightenment will be gratefully received ..
Thanks a lot in advance for any help!!
S
 
Hi Sarah

I thinks its Me.RecordsetClone not Me.Recordset.Clone


Col
 
Hi Col, .. no, that isn't it, but thank you for the suggestion!! ......when i debug the problem appears to be that the combo box is looking at the value of my primary key, ...which aren't the values in my combo drop down list!!!

(did try your idea though!!)

Sarah
 
Hmmmm - I suggest doing the comboBox again with the wizard ane selecting the 3rd option "Find a record on my form....etc etc"

It'll re-do the code for you

Col
 
thanks col..that did the trick!!

For anyone with a similar problem heres the new code
generated by the wizard

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

Set rs = Me.Recordset.Clone
rs.FindFirst "[InvoiceNo] = '" & Me![Combo239] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

...as you can see i needed to remove the 'Str(Nz'
from...
'& Str(Nz(Me![Combo237], 0)) '
 

Users who are viewing this thread

Back
Top Bottom