473,399 Members | 3,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Hyperlink Not Working, Run-time error 7971

Hi,
I'm a newbie here and does not really have any formal training on VBA. I just need help to get my hyperlink to work. I have a form in MS Access with a browse button where a user can select a folder from a specified directory from our network. I was able to get the browse button working where it saves a path that is selected onto the textbox that is set as hyperlink. The problem appears when you click on the hyperlink... it will work a few times and afterwards I get this error message that it cannot follow the hyperlink. If I click the "End" button on the MS VB error message it works again. When I click "Debug" it sends me to the code where FollowHyperlink Me.ReqLink (where Reqlink is the name of my hyperlink box) is highlighted.

Below is my code for the browse button On Click command:

Expand|Select|Wrap|Line Numbers
  1. Private Sub SelFolder_Click()
  2. Me.ReqLink = GetFolder(Me.hWnd, "J:\27 - BSSG\03 - ADMF\13 - Ellipse Change Requests")
  3. End Sub
For the Click command on the Hyperlink:

Expand|Select|Wrap|Line Numbers
  1. Private Sub ReqLink_Click()
  2. FollowHyperlink Me.ReqLink
  3. End Sub
And the code for the Browse Button:


Expand|Select|Wrap|Line Numbers
  1. Private Type BrowseInfo
  2.    hWndOwner As Long
  3.    pIDLRoot As Long
  4.    pszDisplayName As String
  5.    lpszTitle As String
  6.    ulFlags As Long
  7.    lpfnCallback As Long
  8.    lParam As Long
  9.    iImage As Long
  10. End Type
  11.  
  12. Public Const BIF_RETURNONLYFSDIRS = &H1
  13. Public Const BIF_DONTGOBELOWDOMAIN = &H2
  14. Public Const BIF_STATUSTEXT = &H4
  15. Public Const BIF_RETURNFSANCESTORS = &H8
  16. Public Const BIF_EDITBOX = &H10
  17. Public Const BIF_VALIDATE = &H20
  18. Public Const BIF_NEWDIALOGSTYLE = &H40
  19. Public Const BIF_USENEWUI = (BIF_NEWDIALOGSTYLE Or BIF_EDITBOX)
  20. Public Const BIF_BROWSEINCLUDEURLS = &H80
  21. Public Const BIF_UAHINT = &H100
  22. Public Const BIF_NONEWFOLDERBUTTON = &H200
  23. Public Const BIF_NOTRANSLATETARGETS = &H400
  24. Public Const BIF_BROWSEFORCOMPUTER = &H1000
  25. Public Const BIF_BROWSEFORPRINTER = &H2000
  26. Public Const BIF_BROWSEINCLUDEFILES = &H4000
  27. Public Const BIF_SHAREABLE = &H8000
  28. Private Const MAX_PATH = 260
  29. Private Const WM_USER = &H400
  30. Private Const BFFM_INITIALIZED = 1
  31. Private Const BFFM_SELCHANGED = 2
  32. Private Const BFFM_SETSTATUSTEXT = (WM_USER + 100)
  33. Private Const BFFM_SETSELECTION = (WM_USER + 102)
  34.  
  35. Public Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
  36. Public Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BrowseInfo) As Long
  37. Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)
  38. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
  39.  
  40. Private mstrSTARTFOLDER As String
  41. Public Function GetFolder(ByVal hWndModal As Long, Optional StartFolder As String = "", Optional Title As String = "Please select a folder:", _
  42.    Optional IncludeFiles As Boolean = False, Optional IncludeNewFolderButton As Boolean = False) As String
  43.     Dim bInf As BrowseInfo
  44.     Dim RetVal As Long
  45.     Dim PathID As Long
  46.     Dim RetPath As String
  47.     Dim Offset As Integer
  48.     'Set the properties of the folder dialog
  49.     bInf.hWndOwner = hWndModal
  50.     bInf.pIDLRoot = 0
  51.     bInf.lpszTitle = Title
  52.     bInf.ulFlags = BIF_RETURNONLYFSDIRS Or BIF_STATUSTEXT
  53.     If IncludeFiles Then bInf.ulFlags = bInf.ulFlags Or BIF_BROWSEINCLUDEFILES
  54.     If IncludeNewFolderButton Then bInf.ulFlags = bInf.ulFlags Or BIF_NEWDIALOGSTYLE
  55.     If StartFolder <> "" Then
  56.        mstrSTARTFOLDER = StartFolder & vbNullChar
  57.        bInf.lpfnCallback = GetAddressofFunction(AddressOf BrowseCallbackProc) 'get address of function.
  58.    End If
  59.     'Show the Browse For Folder dialog
  60.     PathID = SHBrowseForFolder(bInf)
  61.     RetPath = Space$(512)
  62.     RetVal = SHGetPathFromIDList(ByVal PathID, ByVal RetPath)
  63.     If RetVal Then
  64.          'Trim off the null chars ending the path
  65.          'and display the returned folder
  66.          Offset = InStr(RetPath, Chr$(0))
  67.          GetFolder = Left$(RetPath, Offset - 1)
  68.          'Free memory allocated for PIDL
  69.          CoTaskMemFree PathID
  70.     Else
  71.          GetFolder = ""
  72.     End If
  73. End Function
  74. Private Function BrowseCallbackProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal lp As Long, ByVal pData As Long) As Long
  75.    On Error Resume Next
  76.    Dim lpIDList As Long
  77.    Dim ret As Long
  78.    Dim sBuffer As String
  79.    Select Case uMsg
  80.        Case BFFM_INITIALIZED
  81.            Call SendMessage(hWnd, BFFM_SETSELECTION, 1, mstrSTARTFOLDER)
  82.        Case BFFM_SELCHANGED
  83.            sBuffer = Space(MAX_PATH)
  84.            ret = SHGetPathFromIDList(lp, sBuffer)
  85.            If ret = 1 Then
  86.                Call SendMessage(hWnd, BFFM_SETSTATUSTEXT, 0, sBuffer)
  87.            End If
  88.    End Select
  89.    BrowseCallbackProc = 0
  90. End Function
  91. Private Function GetAddressofFunction(add As Long) As Long
  92.  GetAddressofFunction = add
  93. End Function
*******************
Any help you can provide will be highly appreciated.

Many thanks,
Vspsdca
Aug 22 '08 #1
6 5638
ADezii
8,834 Expert 8TB
In my opinion, your code is much too complicated for such a relatively simple task:
  1. Create a Reference to the Microsoft Office XX.X Object Library
  2. Execute the following code whereever appropriate:
    Expand|Select|Wrap|Line Numbers
    1. Dim strFolderName As String
    2. Dim result As Integer
    3.  
    4. With Application.FileDialog(msoFileDialogFolderPicker)
    5.   .Title = "View Folders For Hyperlink"     'Change if necessary
    6.   .AllowMultiSelect = False        
    7.   .ButtonName = "Select Folder"     'Change if necessary
    8.   .InitialFileName = "C:\Windows\System32\"         'Change
    9.   .InitialView = msoFileDialogViewLargeIcons        'Change if necessary
    10.      result = .Show
    11.      If (result <> 0) Then
    12.        strFolderName = Trim(.SelectedItems.Item(1))
    13.         Me![ReqLink] = strFolderName
    14.      Else
    15.        Me![ReqLink] = vbNullString
    16.      End If
    17. End With
  3. Navigate to the Selected Folder:
    Expand|Select|Wrap|Line Numbers
    1. Application.FollowHyperlink Me![ReqLink], , True
  4. Any questions, don't hesitate to ask.
Aug 24 '08 #2
Thank you for your reply. Being a newbie I hope you wouldn't mind me asking you a few more questions regarding the code you have provided.

1. Do I replace my module code with the the code below or do i leave the module code as is? Do I put on this the On Click event of my browse button?

Execute the following code whereever appropriate:

Code: ( text )
Dim strFolderName As String
Dim result As Integer

With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "View Folders For Hyperlink" 'Change if necessary
.AllowMultiSelect = False
.ButtonName = "Select Folder" 'Change if necessary
.InitialFileName = "C:\Windows\System32\" 'Change
.InitialView = msoFileDialogViewLargeIcons 'Change if necessary
result = .Show
If (result <> 0) Then
strFolderName = Trim(.SelectedItems.Item(1))
Me![ReqLink] = strFolderName
Else
Me![ReqLink] = vbNullString
End If
End With
Navigate to the Selected Folder:

2. Do I put the following code on the On Click event of my hyperlink textbox?

Code: ( text )
Application.FollowHyperlink Me![ReqLink], , True


3. A user ended up pasting a link on the Hyperlink textbox instead of using the browse for folder button, I noticed that when you click on the link the same error occurs. Is it because the code does not accept a link that did not come from the browse for folder button?

Thanks.
Sep 8 '08 #3
ADezii
8,834 Expert 8TB
In my opinion, your code is much too complicated for such a relatively simple task:
  1. Create a Reference to the Microsoft Office XX.X Object Library
  2. Execute the following code whereever appropriate:
    Expand|Select|Wrap|Line Numbers
    1. Dim strFolderName As String
    2. Dim result As Integer
    3.  
    4. With Application.FileDialog(msoFileDialogFolderPicker)
    5.   .Title = "View Folders For Hyperlink"     'Change if necessary
    6.   .AllowMultiSelect = False        
    7.   .ButtonName = "Select Folder"     'Change if necessary
    8.   .InitialFileName = "C:\Windows\System32\"         'Change
    9.   .InitialView = msoFileDialogViewLargeIcons        'Change if necessary
    10.      result = .Show
    11.      If (result <> 0) Then
    12.        strFolderName = Trim(.SelectedItems.Item(1))
    13.         Me![ReqLink] = strFolderName
    14.      Else
    15.        Me![ReqLink] = vbNullString
    16.      End If
    17. End With
  3. Navigate to the Selected Folder:
    Expand|Select|Wrap|Line Numbers
    1. Application.FollowHyperlink Me![ReqLink], , True
  4. Any questions, don't hesitate to ask.
Just subscribing for now, will check back later when I have the time.
Sep 8 '08 #4
ADezii
8,834 Expert 8TB
Thank you for your reply. Being a newbie I hope you wouldn't mind me asking you a few more questions regarding the code you have provided.

1. Do I replace my module code with the the code below or do i leave the module code as is? Do I put on this the On Click event of my browse button?

Execute the following code whereever appropriate:

Code: ( text )
Dim strFolderName As String
Dim result As Integer

With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "View Folders For Hyperlink" 'Change if necessary
.AllowMultiSelect = False
.ButtonName = "Select Folder" 'Change if necessary
.InitialFileName = "C:\Windows\System32\" 'Change
.InitialView = msoFileDialogViewLargeIcons 'Change if necessary
result = .Show
If (result <> 0) Then
strFolderName = Trim(.SelectedItems.Item(1))
Me![ReqLink] = strFolderName
Else
Me![ReqLink] = vbNullString
End If
End With
Navigate to the Selected Folder:

2. Do I put the following code on the On Click event of my hyperlink textbox?

Code: ( text )
Application.FollowHyperlink Me![ReqLink], , True


3. A user ended up pasting a link on the Hyperlink textbox instead of using the browse for folder button, I noticed that when you click on the link the same error occurs. Is it because the code does not accept a link that did not come from the browse for folder button?
1. Do I replace my module code with the the code below or do i leave the module code as is? Do I put on this the On Click event of my browse button?
There has been a slight code modification, replace your code with the following, and yes it can go in the Click() Event of your Browse Button.
Expand|Select|Wrap|Line Numbers
  1. Dim strFolderName As String
  2. Dim result As Integer
  3.  
  4. With Application.FileDialog(msoFileDialogFolderPicker)
  5.   .Title = "View Folders For Hyperlink"     'Change if necessary
  6.   .AllowMultiSelect = False
  7.   .ButtonName = "Select Folder"     'Change if necessary
  8.   .InitialFileName = "C:\Windows\System32\"         'Change
  9.   .InitialView = msoFileDialogViewLargeIcons        'Change if necessary
  10.      result = .Show
  11.      If (result <> 0) Then
  12.        strFolderName = Trim(.SelectedItems.Item(1))
  13.         Me![ReqLink] = strFolderName & "#" & strFolderName
  14.      Else
  15.        Me![ReqLink] = vbNullString
  16.      End If
  17. End With
2. Do I put the following code on the On Click event of my hyperlink textbox?
No code is needed to Navigate via the Hyperlink, as long as the Control Source for the Text Box (ReqLinq) is the HyperLink Data Type. This functionality is self contained within the Data Type, so a single Click will do the trick.
3. A user ended up pasting a link on the Hyperlink textbox instead of using the browse for folder button, I noticed that when you click on the link the same error occurs. Is it because the code does not accept a link that did not come from the browse for folder button?
You can manually enter a Hyperlink Path in any manner you wish, as long as it is valid, you can Navigate to it. You must, however, move off the Field then re-enter it for the Hyperlink to work.
Sep 8 '08 #5
Thanks so much!!!! It finally worked!
Sep 18 '08 #6
ADezii
8,834 Expert 8TB
Thanks so much!!!! It finally worked!
You are quite welcome.
Sep 18 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Salad | last post by:
If I create a field as a hyperlink, Access will open the hyperlink if I single click it. Is there a method within the operating system that would tell access to only open the hyperlink if...
3
by: Kumar | last post by:
Hi Folks, I have a question regarding conditional hyperlink in datagrid. I want to display Hyperlink if my QID values in (1,4,5,6) other wise i want to display just Qdescription with out...
4
by: Lan H. Nguyen | last post by:
I have this line of code in my .aspx page <asp:HyperLink ID="hrefView" CssClass="main" ForeColor="blue" Runat="server" NavigateUrl='<%# "View.aspx?id=" + ID.ToString()%>'>View...
1
by: D. Shane Fowlkes | last post by:
Hello All. I keep asking for help with this on the www.asp.net forums and nobody seems to be able to help. What I'm trying to accomplish is very simple. I simply want to create a Hyperlink...
3
by: sloesch | last post by:
I am working with VS.net 2003, framework 1.1, developing with VB.net, and ASP.net, and I would like to know how you can create a dynamic hyperlink on the fly to a document stored in a SQL database?...
4
by: sulemanzia | last post by:
I have a form with a Command button. i have a text box also which is bound to my Button. i have created a standard module and created an onclick event for my button which is something like this (...
4
by: Mat | last post by:
How do you modify the color of an hyperlink when your mouse go over it? <asp:HyperLink
20
by: tshad | last post by:
I had posted this problem earlier and just noticed that the Hyperlink is the problem. Apparently, it doesn't figure out the path correctly. It uses the path of the file it is in, even if it is...
3
by: Nathan Sokalski | last post by:
I am using the ImageUrl property of the HyperLink control. My image is large, so I am setting the width/height attributes, but when it renders the width/height attributes are in the <atag rather...
1
by: John Devlon | last post by:
Hi, I have a problem using a hyperlink and a frameset... When I run the application, and click on the link, the link is displayed in a new window... But the strange thing is, I set the target...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.