Kiwi-Wombat
Registered User.
- Local time
- Today, 01:44
- Joined
- Aug 2, 2004
- Messages
- 56
Hi
I am having problems with FindFirst. I am trying to search for a word in a specific text field in a table. The text field is not a key field but is indexed.
Prior to calling the following code, varSearch (a string) has been assigned a value by user input. Assume that value is "England"
It stops on FindFirst and gives a Run-time error 3070 - The Microsoft Jet database engine does not recognise 'England' as a valid field or expression.
However (and just for test purposes) if I hard code "England" like this instead of using a varaiable
It correctly stops on the first record that has 'England' in the text field
I obviously have a syntax problem but after 5 hours I can't figure it
Incidentally if varSearch is an integer and I use the same principle as my first example and search on the Key Field (an Autonumber), that works. It is only when the variable is a string that doesn't seem to work
Can anyone help please
Thanks
I am having problems with FindFirst. I am trying to search for a word in a specific text field in a table. The text field is not a key field but is indexed.
Prior to calling the following code, varSearch (a string) has been assigned a value by user input. Assume that value is "England"
Code:
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("MyTable", dbOpenDynaset)
rst.FindFirst "MyTableField = " & varsearch
It stops on FindFirst and gives a Run-time error 3070 - The Microsoft Jet database engine does not recognise 'England' as a valid field or expression.
However (and just for test purposes) if I hard code "England" like this instead of using a varaiable
Code:
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("MyTable", dbOpenDynaset)
rst.FindFirst "[MyTableField] = 'England' "
It correctly stops on the first record that has 'England' in the text field
I obviously have a syntax problem but after 5 hours I can't figure it
Incidentally if varSearch is an integer and I use the same principle as my first example and search on the Key Field (an Autonumber), that works. It is only when the variable is a string that doesn't seem to work
Can anyone help please
Thanks
Last edited: