Preventing System Messages

P

PosseJohn

I would like to present a customized message if the user inputs data that
does not meet the DB structure.

I have a field that is set to Numeric, byte (0-255 allowed).

If the user enters a value greater than 255, the system error message comes
up.

Any way of preventing the application error message and allowing me to
present a customized error message?
 
F

fredg

I would like to present a customized message if the user inputs data that
does not meet the DB structure.

I have a field that is set to Numeric, byte (0-255 allowed).

If the user enters a value greater than 255, the system error message comes
up.

Any way of preventing the application error message and allowing me to
present a customized error message?

You can use code to replace the system message with your own.

Here's how you can find the correct error and show your own message
for any of the form level errors.

First code the Form's Error event:

MsgBox "Error#: " & DataErr ' Display the error number
Response = acDataErrDisplay ' Display Default message

Then open the form and intentionally make that error.

The message box will display the error number and the default error
message.

Next, go back to the Form's error event and change that code to:

If DataErr = XXXX Then
Response = acDataErrContinue ' Don't display the default
message
MsgBox "Present your own message here."
Else
MsgBox "Error#: " & DataErr
Response = acDataErrDisplay ' Display Default message
End If

where XXXX is the error number.
 
P

PosseJohn

Thank you Fred,

Is there a way to capture which control on the form is causing the error?
 
P

Piet Linden

Thank you Fred,

Is there a way to capture which control on the form is causing the error?

I would think you could use Me.ActiveControl and perhaps store that in
a form-level variable... as long as your form doesn't crash, you
should still see it. Then you can do something like...

MsgBox "Control: " & Me.ActiveControl.Name & vbcrlf & "Error#: " &
DataErr

or something similar...
 
F

fredg

Thank you Fred,

Is there a way to capture which control on the form is causing the error?

Depending upon how you got the error (in a text control or after
clicking a command button):

MsgBox "Current Control .. " & Screen.ActiveControl.Name & " ....
Previous Control .. " & Screen.PreviousControl.Name
 

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