Results 1 to 3 of 3
  1. #1
    Hank153 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2012
    Posts
    19

    Command Button Error handling

    I have the following code in the on Click event of a command button on my report:

    Private Sub Command75_Click()
    On Error GoTo PROC_ERR

    PROC_ERR:


    MsgBox "Sorry No Family File Available"
    On Error Resume Next

    Me.Code2.SetFocus
    FollowHyperlink Code2
    End Sub

    The code runs as expected when there is an error (missing hyperlink in code2) -- but it also displays the MsgBox when there is a hyperlink in code2. After the message box is displayed, the hyperlink opens properly.

    What do I need to add to my code to prevent showing the msgbox when there is a hyperlink to display?

  2. #2
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    What that code does is this:
    Code:
    Private Sub Command75_Click()
    For command button Command75, does this when the button is clicked.
    Code:
    On Error GoTo PROC_ERR
    Sets a trigger so that any error that is encountered will send the computer to the spot called PROC_ERR.
    Code:
    PROC_ERR:
    MsgBox "Sorry No Family File Available"
    Names THIS spot PROC_ERR, and pops up a message box.
    Code:
    On Error Resume Next
    Changes the trigger so that any more errors will just continue at the next line.
    Code:
    Me.Code2.SetFocus
    FollowHyperlink Code2
    Sets the active control to be the control called code2, then follows the hyperlink that's supposed to be in code2.
    Code:
    End Sub
    Ends the subroutine.

    That code is executed in order, so it will always pop the message box, before even attempting to open the hyperlink.

    What I think you really want is something more like this.
    Code:
    Private Sub Command75_Click()
    On Error GoTo Err_Command75_Click
    
        Me.Code2.SetFocus
        FollowHyperlink Code2
    
    Exit_Command75_Click:
        Exit Sub
    
    Err_Command75_Click:
        If Err.Number = 490 Then 
           MsgBox "Sorry No Family File Available"
           Resume Exit_Command75_Click
        Else
           MsgBox Err.Description
           Resume Exit_Command75_Click
        End If
    
    End Sub
    NOTES -
    1) I've renamed the error landing spot so that it's associated with the command button.
    2) I've moved it after the exit, so that it won't go off unless there's an error raised.
    3) I'm testing for the "missing link" error, and giving that message only when that particular error is raised. I believe the error for missing hyperlink is 490. I may be wrong. If you run the above code once with a record you know has no family file, then look at the error number and put it in the place where I have the number 490 in the above code, then you should be good. Feel free to make it a list ""If Err.Number = 490 OR 491 OR 492 etc" if you find there are a couple of different possible errors due to missing files.

  3. #3
    Hank153 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2012
    Posts
    19
    Just what I needed. Thanks a lot.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Network error and Command Button error
    By Sandra Williams in forum Access
    Replies: 1
    Last Post: 05-26-2013, 09:25 AM
  2. Error on command button wizard
    By jcor in forum Forms
    Replies: 7
    Last Post: 05-10-2013, 09:34 AM
  3. Replies: 2
    Last Post: 07-24-2012, 12:44 PM
  4. Error Import Command Button
    By kowen091010 in forum Access
    Replies: 4
    Last Post: 12-15-2011, 07:56 AM
  5. Error handling for delete record command
    By jobrien4 in forum Access
    Replies: 2
    Last Post: 09-16-2011, 11:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums