Searching for a record in ADO vs DAO

J

Joe

Hi, I found this example code in the newsgroup here and it is what I
need to do, but I am using ADO instead of DAO. I have successfully
coded all of my record navigation (movefirst, movennext, add new,
delete, etc) so far. I am using a query on an unbound combo box on an
unbound form using the afterupdate property event to go to a specific
record.

I need help adapting this example to ADO since the methods obviously
wont work with my current configuration. Thank you for your help.

Private Sub cboFindContact_AfterUpdate()
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.FindFirst "[FieldToSearch] = " & cboFindRecord
If rs.NoMatch Then
MsgBox "Not Found"
rs.MoveFirst
End If
Me.Bookmark = rs.Bookmark
Set rs = Nothing
End Sub
 
D

Dirk Goldgar

Joe said:
Hi, I found this example code in the newsgroup here and it is what I
need to do, but I am using ADO instead of DAO. I have successfully
coded all of my record navigation (movefirst, movennext, add new,
delete, etc) so far. I am using a query on an unbound combo box on an
unbound form using the afterupdate property event to go to a specific
record.

I need help adapting this example to ADO since the methods obviously
wont work with my current configuration. Thank you for your help.

Private Sub cboFindContact_AfterUpdate()
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.FindFirst "[FieldToSearch] = " & cboFindRecord
If rs.NoMatch Then
MsgBox "Not Found"
rs.MoveFirst
End If
Me.Bookmark = rs.Bookmark
Set rs = Nothing
End Sub


So you're saying that your form's recordset is an ADO recordset, not a DAO
recordset? Is that because you're working in an ADP file, or did you
explcitly set the form's Recordset property to an ADO recordset that you
opened?

If your form's recordset is an ADO recordset, then the equivalent find code
would look like this, I think:

'----- start of code -----
Private Sub cboFindContact_AfterUpdate()

With Me.RecordsetClone
.Find "[FieldToSearch] = " & Me!cboFindContact
If .EOF Then
MsgBox "Not Found"
.MoveFirst
End If
Me.Bookmark = .Bookmark
End With

End Sub
'----- end of code -----
 

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