Synchronous RunSQL/OpenQuery

G

Ghost Dog

Every now and then the code below fails to perform as expected:

' intRandom is a time based random number (always negative)
DoCmd.RunSQL "UPDATE PDA_EDL SET PDA_EDL.IDNumber = " & intRandom &
" WHERE (((PDA_EDL.IDNumber)=0) AND PDA_EDL.UserName = '" & strUser & "')"
DoEvents

' Add records to the EDL table (Appends from PDA_EDL to EDL TABLE
Where IDNumber = intRandom for current user)
DoCmd.OpenQuery ("qryPDANewRecordsAppend")

DoEvents

' Refresh PDA_EDL table with EDL table autonumber and clear update
date field
DoCmd.RunSQL "UPDATE PDA_EDL INNER JOIN [EDL TABLE] ON
(PDA_EDL.DateEdited = [EDL TABLE].AddedDate) AND " & _
"(PDA_EDL.UserName = [EDL TABLE].AddedBy) AND
(PDA_EDL.TagNumber = [EDL TABLE].[MCAP ALPHANUMERIC #]) " & _
"SET PDA_EDL.IDNumber = [EDL TABLE].[IDNUMBER], " &
_
"PDA_EDL.DateEdited = Null WHERE (PDA_EDL.UserName =
'" & strUserID & "')"


The object of the above is to import records from PDA_EDL into [EDL TABLE]

Sample record in PDA_EDL:

IDNumber = 0 (which means its a new record that should be added to [EDL
TABLE])
Tag Number = 111
User = BOB
DateEdited = Aug 15, 2005

The first SQL statement sets the IDNumber in PDA_EDL to (for example) -11809
The OpenQueryLine appends the record into [EDL TABLE], where IDNumber is an
autonumber.
The last SQL statement clears the date edited field and updates the IDNumber
(e.g. -11809) with the autonumber created in [EDL TABLE]

This works 'almost' every time.
Every once in a while the IDNumber in PDA_EDL is negative (which it should
not be), the date edited is cleared, and the record is NOT in [EDL TABLE]

It is almost as if both of the RunSQL commands executed and the append query
failed, but this happens very infrequently.
Is it possible that they execute asynchronously and the second RunSQL
executes during/prior to the OpenQuery?
 

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