Command Buttons & Error Messages & Forms

  • Follow


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!


0
Reply Utf 2/20/2008 9:22:00 PM

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


-- 
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"TomP" <TomP@discussions.microsoft.com> wrote in message 
news:7567A1A7-D628-4BC2-A555-9C64F2273110@microsoft.com...
>
> 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!
>
> 


0
Reply Douglas 2/20/2008 9:31:31 PM


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


"Douglas J. Steele" wrote:

> 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
> 
> 
> -- 
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
> 
> 
> "TomP" <TomP@discussions.microsoft.com> wrote in message 
> news:7567A1A7-D628-4BC2-A555-9C64F2273110@microsoft.com...
> >
> > 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!
> >
> > 
> 
> 
> 
0
Reply Utf 2/21/2008 1:40:00 PM

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.

-- 
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"TomP" <TomP@discussions.microsoft.com> wrote in message 
news:5F097171-B13D-4682-8981-07B8B53D7F85@microsoft.com...
> 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
>
>
> "Douglas J. Steele" wrote:
>
>> 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


0
Reply Douglas 2/21/2008 1:56:02 PM

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

"Douglas J. Steele" wrote:

> 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.
> 
> -- 
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
> 
> 
> "TomP" <TomP@discussions.microsoft.com> wrote in message 
> news:5F097171-B13D-4682-8981-07B8B53D7F85@microsoft.com...
> > 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
> >
> >
> > "Douglas J. Steele" wrote:
> >
> >> 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
> 
> 
> 
0
Reply Utf 2/21/2008 5:27:04 PM

4 Replies
304 Views

(page loaded in 0.086 seconds)


Reply: