'Search' code

Nic

Registered User.
Local time
Today, 13:01
Joined
Jan 15, 2012
Messages
47
Hi,
I have a form and a few tables. On my form i have a few text boxes and a cmd button. When clicked the cmd button looks up data in a table (using info in one text box) and then populates other text boxes on my form from corresponding data to the record being looked up.
My code uses the 'find first' code, and it all works with 'numbers', but i want to search a text file. EG. it all works if looking for a number, but it doesnt work if looking for text.
Hope that makes sense, and any suggestions greatly welcome.
 
When you search on text you need to use a slightly different approach to what you would with numbers.

For numbers you can use;
Code:
[I]Expression[/I].FindFirst "FieldName = " & Me.FormField
For text you need to use;
Code:
[I]Expression[/I].FindFirst "FieldName = [COLOR="Red"]'[/COLOR]" & Me.FormField [COLOR="Red"]& "'"[/COLOR]
Whilst dates are;
Code:
[I]Expression[/I].FindFirst "FieldName = [COLOR="Red"]#[/COLOR]" & Me.FormField [COLOR="Red"]& "#"[/COLOR]

You might also find the search function demonstrated here of some interest
 
Genius!
Thanks for that - how 'should' i know that??
Where are these rules found apart from on forums like this??

Appreciated!
 
I guess you'll find it in the Help files, certainly in your VBA text book, and then experience helps too :)
 

Users who are viewing this thread

Back
Top Bottom