query confirmation of success or failure

S

segurarl

Hello:

I run a few queries in the event forms.

Is there any way to confirm and/or check the query was successfull, maybe
with a message?

Sometimes the query (update ) appears to run and there is no error message
but the records are not updated. This is how I call the query:
Dim stDocName as string
stDocName = "UpdateItemLocation"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Thank you!
 
K

Klatuu

If your queries are action queries (delete, update, append), then I would not
use the openquery method. I would suggest using the Execute method with the
dbFailOnError so that an error will be raised whether the SetWarnings is on
or off. You will also want to add an error handler to your routine to trap
for errors.

CurrentDb.Execute(""UpdateItemLocation"), dbFailOnError
 
S

segurarl

Thanks a lot!!!

Klatuu said:
If your queries are action queries (delete, update, append), then I would not
use the openquery method. I would suggest using the Execute method with the
dbFailOnError so that an error will be raised whether the SetWarnings is on
or off. You will also want to add an error handler to your routine to trap
for errors.

CurrentDb.Execute(""UpdateItemLocation"), dbFailOnError
 
K

Klatuu

You are welcome. Just wanted to add a note in case you want to show a
confirmation message box. The trick would be to put a success message box
after the Execute, and a failure in the Error Handler:

On Error GoTo MyError_Handler
CurrentDb.Execute(""UpdateItemLocation"), dbFailOnError
MsgBox "Update Completed Successfully"

MyRoutine_Exit:

Exit Sub

MyError_Handler:

MsgBox "Update Failed" & vbNewLine & "With Error " & err.Number & " - "
& err.description
GoTo MyRoutine_Exit
End Sub
 

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