M
mekmike1
I have located a record in a recordset. How do I make the form, tied to that
recordset, show that record?
recordset, show that record?
Use the Bookmark property:I have located a record in a recordset. How do I make the form, tied to that
recordset, show that record?
mekmike1 said:Thank you for the response but I am using ADO. This has been extremely
frustrating because there are many resources for DAO but not as many for
ADO.
I have found methods of locating records in recordsets that are tied to
this
form but CANNOT find a way to make the form show that record. It seems
absurd
that vba does not allow you to set me.bookmark = rs.bookmark but I keep
getting the Invalid Bookmark error.
'Open "PCM Interfaces (Main Table) recordset.
Dim rsMainData As New ADODB.Recordset
With rsMainData
.Open "PCM Interfaces (Main Table)", CurrentProject.Connection, _
adOpenKeyset, adLockOptimistic, adCmdTableDirect
.Index = "Search_Index"
.MoveFirst
End With
Dim rsClone As New ADODB.Recordset
Set rsClone = rsMainData.Clone
Me![Search_srl_box].SetFocus
'The filter criteria will eventually include the value of another text box
(AND)
rsClone.Filter = "[Serial Number] ='" & Search_srl_box.Text & "'"
If rsClone.EOF = False Then
Me.Bookmark = rsClone.Bookmark
End If
rsClone.Close
Set rsClone = Nothing
rsMainData.Close
Set rsMainData = Nothing
End Sub
Try this first:Here is the code. Thank you for looking. Is there an answer to my question
because I have other posts related to this and nobody has any solution other
than using DAO code with FindFirst?
Don't use the As New syntax in VBA. Use an explicitPublic Sub Find_Button_Click()
As you're addressing a control, which you normally ever assign a name, useSet rsClone = rsMainData.Clone
Me![Search_srl_box].SetFocus
Use the Find method:'The filter criteria will eventually include the value of another text box
(AND)
rsClone.Filter = "[Serial Number] ='" & Search_srl_box.Text & "'"
If rsClone.EOF = False Then
Me.Bookmark = rsClone.Bookmark
End If
Stefan Hoffmann said:hi,
Try this first:Here is the code. Thank you for looking. Is there an answer to my question
because I have other posts related to this and nobody has any solution other
than using DAO code with FindFirst?
http://support.microsoft.com/kb/195222
http://www.devguru.com/technologies/ado/quickref/recordset_find.html
Otherwise comments will follow inline...
Don't use the As New syntax in VBA. Use an explicitPublic Sub Find_Button_Click()
Set rsMainData = New ADODB.Recordset
This is due to this nice behaviour, which can also happen in some normal
situations:
Dim rs As New ADODB.Recordset
If Not rs Is Nothing Then MsgBox "rs is useable."
Set rs = Nothing
If Not rs Is Nothing Then MsgBox "rs is useable."
It can happen in this case that you use an object which is reinitialized
and thus carries different data.
The MoveFirst is not needed. You only need a
.MoveLast
.MoveFirst
when you want to use RecordCount.
Same as above.
As you're addressing a control, which you normally ever assign a name, useSet rsClone = rsMainData.Clone
Me![Search_srl_box].SetFocus
SearchSrlBox.SetFocus
This makes code reading easier.
Use the Find method:'The filter criteria will eventually include the value of another text box
(AND)
rsClone.Filter = "[Serial Number] ='" & Search_srl_box.Text & "'"
If rsClone.EOF = False Then
Me.Bookmark = rsClone.Bookmark
End If
http://msdn.microsoft.com/en-us/library/ms676117(VS.85).aspx
mfG
--> stefan <--
Are you sure, that this line is executed? It normally works...My problem is that once i find the record in the rsClone and then set the
rs.bookmark = rsClone.boomark
And then nothing else happens. The original form which the recordset and the
recordsetClone were sourced from still is showing the very first record. It
is acting as though setting the recordset bookmark has no effect on which
record is visible in the form.
I was trying to use all ADO to stay consistent but if ADO just does not
have a method of synchronizing a form to a recordset "me.bookmark =
rs.bookmark" or "Me.bookmark = rsClone.bookmark" then I must use DAO which
does allow it.
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.