Click here to Skip to main content
15,915,019 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
VB
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.
VB
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 *****>
Posted
Updated 17-Mar-12 5:10am
v4
Comments
André Kraak 17-Mar-12 11:10am    
Edited question:
Added pre tags

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900