Identify when INSERT query fails

GordonR

Registered User.
Local time
Today, 00:42
Joined
Aug 19, 2003
Messages
29
I have searched on the forum but am a bit punch drunk by all the information here!
I have the following code:
Docmd.setwarnings False
Docmd.openquery "insertquery"
Docmd.setwarnings true
However, if the query fails (e.g. violations) then as the warnings are 'off' it just gets ignored. If they are 'on' then the user (apart from having to confirm) gets a rather technical error message. What I really would like is to trap any error and deal with it myself.
I have seen references to recordset counting e.g. but surely there must be an easy method?
Thanks one and all for your time.
 
Code:
Sub Routine()

    On Error Goto Err_Routine

    DoCmd.SetWarnings False 
    DoCmd.OpenQuery "insertquery" 
    DoCmd.SetWarnings True

Exit_Routine:
    Exit Sub

Err_Routine:
    DoCmd.SetWarnings True
    MsgBox Err.Description, vbExclamation, "Error #" & Err.Number
    Resume Exit_Routine

End Sub
 
Last edited:
Thanks for the reply Mr Mile. However, as setwarnings = false then the err_routine never gets entered - only if the setwarnings = true before the docmd.openquery do I see the msgbox and the error details (as well as all the other warnings!!)
Any thoughts?
 
Hmmm.... how bizarre.
I am running Access 2002 on Win Xp Pro, et tu, mon ami?
 

Users who are viewing this thread

Back
Top Bottom