Form_Load event works differently when debugging?

D

Dean Slindee

I have an Access 2003 .adp project with a detail form that is instantiated
by another search form.
If there is a value in the OpenArgs of the detail form, then it is to
display the row with that key value.
This works fine with a SQL Server 2000 backend, but not with a SQL Server
2005 backend.
Except, if I place a breakpoint within the If statement, then it works fine
in SQL Server 2005 as well.
With a breakpoint in place, it works every time in SQL Server 2005.

Is there any "Wait" statement that can be added to remedy this difference?
(For instance, adding a DoEvents statement after each of the first three rs
statements below gets it to work about 50% of the time). It appears that
the logic is correct as it stands. Perhaps it's a timing issue with rs.Find
or RecordsetClone in the SQL2005 interface?

Here is the code from the detail form:
Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
'find the record that matches OpenArgs
Dim rs As ADODB.Recordset
Set rs = Me.RecordsetClone
rs.Find "MailingID = " & Me.OpenArgs
If Not rs.EOF Then
Me.Bookmark = rs.Bookmark
End If
End If
End Sub
 
B

Brendan Reynolds

Dean Slindee said:
I have an Access 2003 .adp project with a detail form that is instantiated
by another search form.
If there is a value in the OpenArgs of the detail form, then it is to
display the row with that key value.
This works fine with a SQL Server 2000 backend, but not with a SQL Server
2005 backend.
Except, if I place a breakpoint within the If statement, then it works
fine in SQL Server 2005 as well.
With a breakpoint in place, it works every time in SQL Server 2005.

Is there any "Wait" statement that can be added to remedy this difference?
(For instance, adding a DoEvents statement after each of the first three
rs statements below gets it to work about 50% of the time). It appears
that the logic is correct as it stands. Perhaps it's a timing issue with
rs.Find or RecordsetClone in the SQL2005 interface?

Here is the code from the detail form:
Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
'find the record that matches OpenArgs
Dim rs As ADODB.Recordset
Set rs = Me.RecordsetClone
rs.Find "MailingID = " & Me.OpenArgs
If Not rs.EOF Then
Me.Bookmark = rs.Bookmark
End If
End If
End Sub


I haven't tested this, but maybe a rs.MoveLast before the rs.Find?
 

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