Command Buttons & Error Messages & Forms

T

TomP

I want to pass my many thanks to your team for all your inputs! You've been
great!! THANK YOU!!

Question: When I insert a command button on the form, I notice that the
Error event does not recognize my instruction to modify a default error
message. On the other hand, I do get the modified message when I click on
the navigation bar on the form to add a new record. Again, my command button
does not recognize the code. See below

Private Sub Form_Error(DataErr As Integer, Response As Integer)

If DataErr = 3314 Then
MsgBox "Please ensure that you enter a caseload type before you
continue!", vbCritical, "Caseload Type Error Message"
Response = acDataErrContinue
Else
Response = acDataErrDisplay
End If

End Sub

Here is the command button code

Private Sub Command259_Click()

On Error GoTo Err_Command259_Click

DoCmd.GoToRecord , , acNewRec

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FormSeeker"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command259_Click:
Exit Sub

Err_Command259_Click:
MsgBox Err.Description
Resume Exit_Command259_Click

End Sub

NOTE: I haven't entered any codes to modify the command button, because I
couldn't make it work. The command button works fine, but what happens is
when I get a default error message "You can't go to the specified record" ,
I click OK and move on. It would be nice if I could modify it to be more
specific. PLEASE don't tell me that it is Error 2105. I've been in an
endless loop trying to make it work. I've tried it and still can't change
that message.

Thank you again for your help!
 
D

Douglas J. Steele

Since you've put Error Handling inside the procedure for Command259_Click,
the code in Form_Error isn't invoked.

Try changing

Err_Command259_Click:
MsgBox Err.Description
Resume Exit_Command259_Click

to

Err_Command259_Click:
Select Case Err.Number
Case 3314
MsgBox "Please ensure that you enter a caseload type before you
continue!", vbCritical, "Caseload Type Error Message"
Case Else
MsgBox Err.Description
End Select
Resume Exit_Command259_Click
 
T

TomP

Here is what I entered and it did not work.... I still get the "You can't
go to the specified record".

Thank you,


Private Sub Command259_Click()

On Error GoTo Err_Command259_Click

DoCmd.GoToRecord , , acNewRec

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FormSeeker"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command259_Click:
Exit Sub

Err_Command259_Click:

Select Case Err.Number
Case 3314
MsgBox "Please ensure that you enter a caseload type before you
continue!", vbCritical, "CASELOAD TYPE Error Message"
Case Else
MsgBox Err.Description
End Select
Resume Exit_Command259_Click

End Sub
 
D

Douglas J. Steele

Change

Case Else
MsgBox Err.Description

to

Case Else
MsgBox Err.Number & ": " & Err.Description

You'll get the error number (followed by a colon) before the error message.
 
T

TomP

Thank you so much! It finally worked! The error code is 2105 and I changed
it on the command button. See below.

Observation: If I didn't use the command button to add a new record and use
the navigation button on the main form, the code to modify the error message
would be 3314.

Have a great day!!!

Private Sub Command259_Click()

On Error GoTo Err_Command259_Click

DoCmd.GoToRecord , , acNewRec

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FormSeeker"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command259_Click:
Exit Sub

Err_Command259_Click:

Select Case Err.Number
Case 2105
MsgBox "Please ensure that you enter a caseload type before you
continue!", vbCritical, "CASELOAD TYPE Error Message"
Case Else
MsgBox Err.Number & ":" & Err.Description

End Select
Resume Exit_Command259_Click

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