How can I customize the dbFailOnError Message

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When a dbFailOnError message occurs, I would like to customize the message.
Also, I would like to issue a doCmd.Close instruction after the message is
displayed.

How would I do this?

Thank you.
 
Andy said:
When a dbFailOnError message occurs, I would like to customize the message.
Also, I would like to issue a doCmd.Close instruction after the message is
displayed.


How are you using dbFailOnError? Typically you should just
use the everyday errorhandling to catch the errors and
generate your own messages. You are using an On Error GoTo
statement, aren't you?
 
No, I am using it as part of executing an insert query. I have tried to use
the On Error, but it kept triggering the error in the function. When I
removed the On Error, the method worked fine. I need the customized message
should any future problems arise and the user can notify the DBA that there
is a problem as well as where and what the problem is.
 
Without seeing your code, it's hard to accurately give advice. But, here's
some anyway. :-)

When you use On Error GoTo... the error-handling portion should be at the
end of your function/subroutine. Typically, there's a statement label
before the handler to exit the function when there is no error (or after
your error-handler finishes handling the error) so the error-handler doesn't
accidentally execute. So, here's a very basic example:

Function InsertRecords()
Dim strSQL as String
strSQL="Insert whatever into whatever"
On Error Goto Err_Execute
CurrentDb.Execute strSQL, dbFailOnError
MsgBox "Insert successful"

Function_Exit:
Exit Function

Err_Execute:
MsgBox "Error executing the insert"
Resume Function_Exit
End Function

Hope this helps.
 
Note that dbFailOnError is an all or nothing kind of thing.
If you expect any kind of error (e.g. duplicate key) during
the normal execution of the insert query, then you're going
to have to restructure your query to avoid those situations
if you want to trap other query failures.

What error(s?) are you trying to generate a custom message
for?

What error(s?) do you expect and want to ignore under normal
circumstances?
 
Back
Top