Results 1 to 5 of 5
  1. #1
    Mnelson is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    7

    Question Application.FollowHyperlink throwing Exception

    Say for instance I had the following code.



    Code:
    Private Sub Command43_Click()
    Select Case Me.Vehicle_Number
    Case "1"
    Application.FollowHyperlink "http://mywebsite/car1"
    Case "2"
    Application.FollowHyperlink "http://mywebsite/car2"
    Now I've programmed the links for every Case that I have from 1-1000. What I've done is synced the case number with the hyperlink on my site. So car vehicle 1, which is also case 1 is linked to the car album 1 on my site. But I haven't created the real webpage for every case yet and I wont need to for quite some time.

    Heres what Im trying to do. I want to throw an exception to the user that there is no website for the corresponding case number. As of now it just throws a debug error, i do not want this. rather i would like:

    have an exception or error box pop up telling the user the page hasn't been created
    or
    to have the button gray itself out when the page hasn't been created yet

    Any tips or code examples would be great. Thanks!

  2. #2
    help_me_with_access is offline help_me_with_excel
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    262
    there's nothing wrong with err handlers. get the error number and description by erroring it out on purpose, then write a handler, which all code should have anyway.

    ALWAYS check for err.number and err.description in visual basic, simply because many errors are assigned the same number, but that combination of properties should never be equal.

    so, for instance:

    Code:
    sub testRoutine()
    
    on error goto errHandle
    
    PrimaryCodeBlock:
      app.followlink "link"
      ...
      ...
      ...
    
    SecondaryCodeBlock:
      'do other stuff if your error happens
      ...
      ...
      ...
    
    exit sub
    
    errHandle:
      if err.number = TargetEnumValue and err.description = "what the error tells you here" then
        'tell the user that the link does exist and exit or go to a labeled line...
        goto SecondaryCodeBlock
      else
        msgbox "an error occurred!  see the administrator!"
      end if
    
    end sub

  3. #3
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    FYI, if all the pages follow that pattern, you can have one line:

    Application.FollowHyperlink "http://mywebsite/car" & Me.Vehicle_Number

    I would assume that the code is not throwing an error, rather the internet browser opens to an error page. If the pages are on your server somewhere, you could use the Dir() function to test for the existence of the file before opening.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    thecsmith70 is offline Novice
    Windows 2K Access 2007
    Join Date
    Sep 2014
    Posts
    15
    Hi - how do you use the Dir() function?

    I use the similiar line: Application.FollowHyperlink "\\c:name of folder\" for my link.

    If the folder is not there, I want a message box to pop up and says "Cant find folder...please locate it manually or create a new folder" instead of a run-time error message.

  5. #5
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You use it inside the Len() function and test that the length is greater than zero.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 11-21-2011, 04:38 PM
  2. Exception in unique field
    By neo651 in forum Access
    Replies: 2
    Last Post: 07-01-2011, 02:23 PM
  3. Exception Reporting - Continued
    By shexe in forum Queries
    Replies: 11
    Last Post: 09-20-2010, 11:20 AM
  4. Exception Reporting
    By shexe in forum Queries
    Replies: 16
    Last Post: 09-09-2010, 09:14 AM
  5. Set IE window size using followhyperlink
    By AndrewAfresh in forum Access
    Replies: 0
    Last Post: 11-23-2006, 12:22 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