how to check if docmd successful

pb21

Registered User.
Local time
Today, 09:07
Joined
Nov 2, 2004
Messages
122
I have the following that appends data from one table to another:
(I didnt print the sql string as you know what it does)

If Not RstAppend.BOF And Not RstAppend.EOF Then
'if data in recordset do something

DoCmd.SetWarnings False

DoCmd.RunSQL StrQry

The sql string appends from one table to another. If the data from the temp table cannot be validated it does not append to the main table. Is there a way of knowing with the warnings off if the docmd was unsuccessful? Without looking in the two tables.

the warnings were off to avoid the user having to click ok to update the main table everytime.

regards
 
try
currentdb.execute strQry
it's faster
it doesn't leave warnings off if the query errors
and it is less typing!

you are in JET?
poke around at
currentdb.recordsaffected
immediately after .execute

izy
 
DBengine error count

Your suggestions work great. I have a last piece of code that only needs to run if no error occurred:

If DBEngine.Errors.Count = 0 Then
MsgBox (Rcount & " " & Strmessage & " added to datastore")
' now save spreadsheet as processed
Dim Today
Today = Now ' Assign current system date and time.
Today = Format(Today, "dd mm yy - hh mm")
endfilename = StrAgentDSN & "Eif" & StrGroupID & "Processed-" & Today & ".XLS"

objXLBook.SaveAs "D:\datastore\Processed EIFs\" & endfilename
Kill "D:\datastore\EIF Awaiting processing\" & filename
End If

*******************
I used the error count =0 to create the condition but once an error occurs then it doesnt go back to zero so the last section within the IF statement does not evaluate even if no error occurs.

Anyone have any idea to get around that. The error count variable is read only so i cannot reset it.

regards in advance
 
a small clarification: i should have said - replace ALL of
docmd.setwarnings false
docmd.runsql strQry
docmd.setwarnings true

with
currentdb.execute strQry

moving along:
not a clue since i rarely visit the errors collection!
Clear works on the err object
?? does it work on the collection?
can you iterate thru the collection and .Remove each item?

izy
 

Users who are viewing this thread

Back
Top Bottom