Error Handling

  • Thread starter szag via AccessMonster.com
  • Start date
S

szag via AccessMonster.com

Pretty new to error handling - if they haven't selected required fields how
can I subsitute a personalized message rather than the generic "You must
enter a table/field field" and make sure the personalizxed doesn't come up
followed by the generic access message? Thanks!
 
M

Marshall Barton

szag said:
Pretty new to error handling - if they haven't selected required fields how
can I subsitute a personalized message rather than the generic "You must
enter a table/field field" and make sure the personalizxed doesn't come up
followed by the generic access message? Thanks!


That kind of error is usually a form error so try using the
form's Error event:

Select Case DataErr
Case <put the error number here>
MsgBox "your error message", . . .
Resonse = acDataErrContinue
Case Else
MsgBox Err.Number & " - " & Err.Description
End Select
Resonse = acDataErrContinue
 
S

szag via AccessMonster.com

Thanks! The only problem there is no error message # that comes up. Just a
the usual little access message that says "You must enter a value in the
'T_Jobs_Quote.forQuote' field". With the name of the Dbase in the upper left
corner. The user never knows what these messages mean so if I can figure out
a way to handle this when required fields are not filled out that would be
great.
 
M

Marshall Barton

If you add the form's Error event code and then put a break
point on the select case statement, you should be able to
see the value of Err.Number by hust moving the mouse over
it.
 
S

szag via AccessMonster.com

Sorry Marshall - as I said pretty much a newbie but I really want to figure
this out for future use. So I basically just copied below into the on error
event. Added Breakpoint (F9) on "Select Case DataErr". When I simulated the
data entry it highlighted the first line in yellow, second line in red. No
value when I hovered over anything though. I am probably missing something?

Private Sub Form_Error(DataErr As Integer, Response As Integer)
Select Case DataErr
Case <put the error number here>
MsgBox "your error message", . . .
Resonse = acDataErrContinue
Case Else
MsgBox Err.Number & " - " & Err.DESCRIPTION
End Select
Resonse = acDataErrContinue
End Sub

Marshall said:
If you add the form's Error event code and then put a break
point on the select case statement, you should be able to
see the value of Err.Number by hust moving the mouse over
it.
Thanks! The only problem there is no error message # that comes up. Just a
the usual little access message that says "You must enter a value in the
[quoted text clipped - 19 lines]
 
D

Douglas J. Steele

Does your code actually have <put the error number here> in it? The
expectation is that you'd put an error number there...

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


szag via AccessMonster.com said:
Sorry Marshall - as I said pretty much a newbie but I really want to
figure
this out for future use. So I basically just copied below into the on
error
event. Added Breakpoint (F9) on "Select Case DataErr". When I simulated
the
data entry it highlighted the first line in yellow, second line in red. No
value when I hovered over anything though. I am probably missing
something?

Private Sub Form_Error(DataErr As Integer, Response As Integer)
Select Case DataErr
Case <put the error number here>
MsgBox "your error message", . . .
Resonse = acDataErrContinue
Case Else
MsgBox Err.Number & " - " & Err.DESCRIPTION
End Select
Resonse = acDataErrContinue
End Sub

Marshall said:
If you add the form's Error event code and then put a break
point on the select case statement, you should be able to
see the value of Err.Number by hust moving the mouse over
it.
Thanks! The only problem there is no error message # that comes up. Just
a
the usual little access message that says "You must enter a value in the
[quoted text clipped - 19 lines]
End Select
Resonse = acDataErrContinue
 
M

Marshall Barton

Replace <put the error number here> with a dummy number so
the code can be compiled. Then you should be able to see
the actual number and put it in instead of the dummy number.
--
Marsh
MVP [MS Access]

Sorry Marshall - as I said pretty much a newbie but I really want to figure
this out for future use. So I basically just copied below into the on error
event. Added Breakpoint (F9) on "Select Case DataErr". When I simulated the
data entry it highlighted the first line in yellow, second line in red. No
value when I hovered over anything though. I am probably missing something?

Private Sub Form_Error(DataErr As Integer, Response As Integer)
Select Case DataErr
Case <put the error number here>
MsgBox "your error message", . . .
Resonse = acDataErrContinue
Case Else
MsgBox Err.Number & " - " & Err.DESCRIPTION
End Select
Resonse = acDataErrContinue
End Sub

Marshall said:
If you add the form's Error event code and then put a break
point on the select case statement, you should be able to
see the value of Err.Number by hust moving the mouse over
it.
Thanks! The only problem there is no error message # that comes up. Just a
the usual little access message that says "You must enter a value in the
[quoted text clipped - 19 lines]
End Select
Resonse = acDataErrContinue
 
S

szag via AccessMonster.com

I think I am closer. It definately is reading my error code # now. The
message box I entered pop's up like I want it to BUT after I hit ok it still
gives me the "You must enter a value in the 'T_Jobs_quote.forQoute' field"
message. I am trying to figure out how I can have my message only and not
this confusing message (for the end user). Thanks.

Marshall said:
Replace <put the error number here> with a dummy number so
the code can be compiled. Then you should be able to see
the actual number and put it in instead of the dummy number.
Sorry Marshall - as I said pretty much a newbie but I really want to figure
this out for future use. So I basically just copied below into the on error
[quoted text clipped - 22 lines]
 
M

Marshall Barton

What was the form doing when the error occured? I guess
it's starting to sound like the form was trying to save the
record (because you tried to close the form or navigate to
another record??). **IF** I'm guessing correctly, then you
should probably add code to the form's BeforeUpdate event to
make sure the field has a value and cancel the event (to
prevent the error from happening). Try something like:

If IsNull(Me.thetextbox) Then
Msgbox "your error message", . . .
Me.thetextbox.Setfocus
Cancel = true
End If
 

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