recordset.find question

G

Guest

I am attempting to display a record in bound combo boxes using the movefirst
/ find commands but I can't seem to get it to work, (noting happens) any
suggestions would be appreciated. my code is below.

Dim rs As Recordset
Dim strSearch As String
Set rs = Me.Recordset.Clone

strSearch = "(VehLicence = '321abc')"

rs.MoveFirst
rs.Find strSearch
 
D

Dirk Goldgar

Arnold Klapheck said:
I am attempting to display a record in bound combo boxes using the
movefirst / find commands but I can't seem to get it to work, (noting
happens) any suggestions would be appreciated. my code is below.

Dim rs As Recordset
Dim strSearch As String
Set rs = Me.Recordset.Clone

strSearch = "(VehLicence = '321abc')"

rs.MoveFirst
rs.Find strSearch

I'm assuming this code is running behind a form. Is it in an MDB or in
an ADP? I'm not sure what you mean by "display a record in bound combo
boxes", but the following code should work to position a form in an MDB
to the first record that matches your search criteria:

Dim strSearch As String

strSearch = "(VehLicence = '321abc')"

With Me.RecordsetClone
.FindFirst strSearch
If .NoMatch Then
MsgBox "No matching record was found."
Else
Me.Bookmark = .Bookmark
End If
End With

The above code is for an MDB, so it assumes that the form's recordset is
a DAO recordset (not an ADO recordset) and uses the DAO methods.

In an ADP you would do this slightly differently, as the form's
recordset would be an ADO recordset with different methods; however,
MDBs are more common so I've assumed that's what you're working with.
 
G

Guest

Arnold Klapheck said:
I am attempting to display a record in bound combo boxes using the movefirst
/ find commands but I can't seem to get it to work, (noting happens) any
suggestions would be appreciated. my code is below.

Dim rs As Recordset
Dim strSearch As String
Set rs = Me.Recordset.Clone

strSearch = "(VehLicence = '321abc')"

rs.MoveFirst
rs.Find strSearch

Add:
Me.Bookmark = rs.Bookmark

to the end.

Barry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top