I've had this adp working fine for several years (Access 2003). In some forms, I have lookup combo boxes to find a record in the form. Pretty standard stuff with the following in the combo box's after update event:
Dim rs as RecordSet
Set rs = Me.RecordsetClone
Rs.Find "CustID = " & me.cboFindCustomer
Me.Bookmark = Ms.Bookmark
Like I said. It's working fine in several forms.
A little background. I have 2 tables in a parent/child relationship.
Customers
and
CustomerEmployees
. Each has it's own separate form for editing the data. Yesterday I added a button to the
CustomerEmployees
form that lets the user open the related parent
Customer
record in a different form. I'm passing the parent's ID to the parent form in the
OpenArgs
parameter. In the
OnOpen
event of the
Customer
form I am running the code above but I'm saving the
openArgs
value to a variable first.
If Not IsNull(Me.OpenArgs) Then
Dim lParentID as long
lParentID = Me.OpenArgs
Dim rs as RecordSet
Set rs = Me.RecordsetClone
Rs.Find "CustID = " & lParentID
Me.Bookmark = Ms.Bookmark
End If
Sometimes it works and sometimes it doesn't. When I step through the code, the
lParentID
has the correct value but I get this error:
"Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record."
If I comment out all the find code above and just let it go to the first record in the form and then use the lookup combo box on the form, that works. The record in question does exist in the form's recordset but for some reason in the
OnOpen
event it's failing. I tried putting the code in the
OnLoad
event but got the same results.
Any suggestions?
<****** UPDATE TO QUESTION ****>
What's odd is if I put a
MsgBox rs.RecordCount
line before the
Find
line, it works. It tells me how many rows I have in the data and it also doesn't give me an error on the
Find
. So I added a Sleep for 1/2 second instead and that seems to work also. Not very graceful. Must be a better solution.
<***** UPDATE TO QUESTION *****>