Re: Where to put my Error handling Code

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Pamela,

I just did a quick test and was able to use something like this instead:

Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr = 2279 Then
MsgBox "Sorry, you must enter a 5-digit code.", vbExclamation, "Wrong
Code!"
Me.TextboxName.Undo
Response = acDataErrContinue
End If
End Sub

Hope that helps...


"Pamela" wrote:

So how do I get the real error code?? All it keeps giving me is "0 --". I
even tried double checking the standard Access error message but it doesn't
give a code - it just says that the entry is invalid for the input mask...
Thanks!

"theDBguy" wrote:

Hi Pamela,

I think error number 0 means there's no error. Let's pretend that the actual
error number is 2501, then try this code in your form's Error event:

Private Sub Form_Error(DataErr As Integer, Response As Integer)
If Err.Number = 2501 Then
MsgBox "Sorry, you must enter a 5-digit code.", vbExclamation, "Wrong Code!"
Me.TextboxName.Undo
Me.TextboxName.SetFocus
End If
End Sub

(untested)
Hope that helps...


"Pamela" wrote:

Hi DB,
I took what you gave me and tried putting it back with my own code (from the
book LOL) and it almost worked!! My error message popped up but then I think
focus needs to be returned to that control so that the user can change it.
Right now, after clicking OK to my error message, the standard message also
opens which then returns focus to the control. I tried to add
Me.AssnNumber.SetFocus to the end of the the code, before the End If but it
doesn't seem to be working. Any suggestions?? Again, thanks so much for
your help - I fully recognize that you and everyone here is giving great
help, it's just my own learning that I'm stumbling over.
Pamela

"theDBguy" wrote:

Hi Pamela,

I tried to give you an example of code that you could put in the Form's
Error event to display the Error number generated when the user violates your
Input Mask.

Have you tried it?


"Pamela" wrote:

Hi Marshall,
If I do this on the Form's OnError Event, will this be THE error message
that pops up for EVERY error that may occur? I have other controls on this
form for which this message would not be appropriate. Also, you have listed
"Case <error number> -- what is this error number and where do I get it?
Someone else mentioned that I have it (Err.Number) in "my" code but the error
code I have listed here is just something I tried to copy and tweak out of an
Access Help book - it isn't based on my understanding. I assumed from my
book that Err.Number is a command, procedure, function (whatever) that Access
recognizes but it certainly doesn't specifically refer to anything I've done
on my form. Thanks for any additional help!

"Marshall Barton" wrote:

Pamela wrote:

I have a control that needs a specific 5 digit number to be entered. I have
an input mask on this control requiring the 5 numbers but if the user doesn't
enter it correctly the system gives a very non-user-friendly error message.
I'd like to replace this message explaining again that it needs to be the
full 5 digit number. I tried entering it in AfterUpdate and OnDirty events
but it seems that the system's Error handling fires first and I still get
their error message. From where does this fire that I can replace it?? I
don't have any other code attached to this control and most other posts here
speak to handling the errors w/ other code. Just in case you need it, here's
my code and it may well need tweaking!
On Error GoTo AssnNumberErr
AssnNumberErr:
If Err.Number Then
MsgBox "Please enter the 5 digit CAP Number"
End If


Try using the Form's Error event:

Select Case DataErr
Case <the error number>
MsgBox "Please enter the 5 digit CAP Number"
Case Else
MesgBox DataErr & " - " & Error(DataErr)
End Select

--
Marsh
MVP [MS Access]
.

.



Relevant Pages

  • Re: Where to put my Error handling Code
    ... focus needs to be returned to that control so that the user can change it. ... Right now, after clicking OK to my error message, the standard message also ... Error event to display the Error number generated when the user violates your ... MsgBox "Please enter the 5 digit CAP Number" ...
    (microsoft.public.access.formscoding)
  • RE: Combo Box Integrity
    ... The error message now is: Run time Error 3020, ... Private Sub Combo24_AfterUpdate ... ' Find the record that matches the control. ... Dim rs As Object ...
    (microsoft.public.access.forms)
  • Re: Where to put my Error handling Code
    ... "Pamela" wrote: ... My error message popped up but then I think ... focus needs to be returned to that control so that the user can change it. ... Error event to display the Error number generated when the user violates your ...
    (microsoft.public.access.formscoding)
  • RE: Error communicating with the OLE server or ActiveX Control
    ... was communicating with the OLE server or ActiveX Control. ... It doesn't seem to matter what code I have in the OnClick Event Procedure. ... Private Sub CancelQueryCmdButton_Click ... I sometimes get that error message. ...
    (microsoft.public.access.formscoding)
  • Re: Unfriendly error message in date field
    ... Use the form's Error event. ... Private Sub Form_Error(DataErr As Integer, Response As Integer) ... > cannot get in front of that error message. ...
    (microsoft.public.access.formscoding)