Results 1 to 6 of 6
  1. #1
    christ2000 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    45

    Question Help With error Runtime 490

    Hello guys, I using the following code to open a network hyperlink to a pdf file, when the file exist it work perfect, the problem is if the pdf do not exist show error 490. my question is how avoid this error and just show for example a message showing THIS DOCUMENT DO NOT EXIST.

    this is the code I am using now:

    Private Sub Command22_Click()
    Dim FileName As String


    Dim Filepath As String
    FileName = Me.analysthide & "_Receipt_" & Me.[MonthsCombo] & "_" & Me.[year]
    Filepath = "Path to file " & FileName & ".pdf"
    Application.FollowHyperlink Filepath
    End Sub

    thanks

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Add some error handling like this:
    Code:
    Private Sub Command22_Click()
    
        Dim FileName As String
        Dim Filepath As String
        
        On Error GoTo err_chk
        FileName = Me.analysthide & "_Receipt_" & Me.[MonthsCombo] & "_" & Me.[Year]
        Filepath = "Path to file " & FileName & ".pdf"
        Application.FollowHyperlink Filepath
        On Error GoTo 0
        
        Exit Sub
        
    err_chk:
        If Err.Number = 490 Then
            MsgBox "THIS DOCUMENT DOES NOT EXIST"
        Else
            MsgBox Err.Number & ": " & Err.Description
        End If
        
    End Sub

  3. #3
    christ2000 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    45

    Thanks Work perfect

    Thanks Work perfect

  4. #4
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You are welcome!

  5. #5
    christ2000 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    45
    Hello if I want to use this code for another errors can I ? for example if I try to open a pdf a this exits but I click cancel and not open the pdf, now show system message 16388, I just want show any text if user select close and no open the pdf, thanks

  6. #6
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Yes, you can use this error handling structure to handle most errors.
    You can specify specific messages for certain error codes, and let the others go to the default messages, like we did with the original question.

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

Similar Threads

  1. Runtime error
    By nick243 in forum Programming
    Replies: 2
    Last Post: 05-18-2016, 09:05 AM
  2. Replies: 3
    Last Post: 02-26-2016, 12:34 PM
  3. Replies: 2
    Last Post: 08-22-2015, 11:26 AM
  4. Replies: 2
    Last Post: 10-15-2014, 04:23 AM
  5. Replies: 13
    Last Post: 06-12-2012, 09:52 PM

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