using textbox value to find record in recordset

D

Deen

How to retrive a record in my recordset by using a value that i type in the
textbox ? Consider i have recordset name : rst. and a field name : LastName.
Then i use textbox name : txtLastName to find the specific record in LastName
field(table).

it's working when i use the txtID ( dim as long ) but not with txtLastName (
dim as string ). What realy is the datatype for txtLastName ?
 
K

Ken Sheridan

It’s the data type of the LastName field that's important here. This will be
Text so, unlike with a number, the value will have to be wrapped in quotes
characters. Literal quotes characters in a string expression are indicated
by using doubled quotes characters so if for instance you want to go to the
first record in a form which matches the name the code would be:

Dim rst As Object

Set rst = Me.Recordset.Clone

rst.FindFirst "LastName = """ & txtLastName & """"
Me.Bookmark = rst.Bookmark
 
Top