Results 1 to 7 of 7
  1. #1
    PMal is offline Novice
    Windows 11 Office 365
    Join Date
    Jul 2022
    Posts
    12

    Add Hyperlink Via Button

    Hello,

    I have a form which contains a hyperlink to a document. Each record should have a document attached and, being lazy, I want to avoid right click - link-edit and just add the destination at the click of a button. I've added the 'add link' button to my form but at present, this doesn't do anything. Is there any code I can put behind it to open up the address box for a hyperlink.

    Hope this makes sense.



    Click image for larger version. 

Name:	Form.jpg 
Views:	12 
Size:	58.9 KB 
ID:	48434

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    1. your doc link does not seem complete, i needs c:\folder\....

    2. I use this code to open anything.
    if the value in the textbox is a word doc file, it will open in word, same for excel, etc
    it just needs the full path to the doc.


    'whatever path is in the textbox will open in its native application
    OpenNativeApp txtBox


    paste this code into a module
    Code:
    #If Win64 Then      'Public Dclare PtrSafe Function
      Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
      Private Declare PtrSafe Function GetDesktopWindow Lib "user32" () As Long
    #else
      Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
      Private Declare Function GetDesktopWindow Lib "user32" () As Long
    #End If
    
    
    Const SW_SHOWNORMAL = 1
    Const SE_ERR_FNF = 2&
    Const SE_ERR_PNF = 3&
    Const SE_ERR_ACCESSDENIED = 5&
    Const SE_ERR_OOM = 8&
    Const SE_ERR_DLLNOTFOUND = 32&
    Const SE_ERR_SHARE = 26&
    Const SE_ERR_ASSOCINCOMPLETE = 27&
    Const SE_ERR_DDETIMEOUT = 28&
    Const SE_ERR_DDEFAIL = 29&
    Const SE_ERR_DDEBUSY = 30&
    Const SE_ERR_NOASSOC = 31&
    Const ERROR_BAD_FORMAT = 11&
    
    
    
    
    Public Sub OpenNativeApp(ByVal psDocName As String)
    Dim r As Long, msg As String
    
    
    r = StartDoc(psDocName)
    If r <= 32 Then
        'There was an error
        Select Case r
            Case SE_ERR_FNF
                msg = "File not found"
            Case SE_ERR_PNF
                msg = "Path not found"
            Case SE_ERR_ACCESSDENIED
                msg = "Access denied"
            Case SE_ERR_OOM
                msg = "Out of memory"
            Case SE_ERR_DLLNOTFOUND
                msg = "DLL not found"
            Case SE_ERR_SHARE
                msg = "A sharing violation occurred"
            Case SE_ERR_ASSOCINCOMPLETE
                msg = "Incomplete or invalid file association"
            Case SE_ERR_DDETIMEOUT
                msg = "DDE Time out"
            Case SE_ERR_DDEFAIL
                msg = "DDE transaction failed"
            Case SE_ERR_DDEBUSY
                msg = "DDE busy"
            Case SE_ERR_NOASSOC
                msg = "No association for file extension"
            Case ERROR_BAD_FORMAT
                msg = "Invalid EXE file or error in EXE image"
            Case Else
                msg = "Unknown error"
        End Select
    '    MsgBox msg
    End If
    End Sub
    
    
    
    
    Private Function StartDoc(psDocName As String) As Long
    Dim Scr_hDC As Long
    
    
    Scr_hDC = GetDesktopWindow()
    StartDoc = ShellExecute(Scr_hDC, "Open", psDocName, "", "C:\", SW_SHOWNORMAL)
    End Function

  3. #3
    PMal is offline Novice
    Windows 11 Office 365
    Join Date
    Jul 2022
    Posts
    12
    I don't think I explained what I want very well. I have no issues with opening the hyperlink as it is just a file path to the network drive.

    at present to add a hyper link, I right click the text box - > select 'Hyperlink' -> select 'edit hyperlink' and then the search box pops up (as pictured). I want to be lazy and add a button next to the text called 'Add Link' so the address box appears with one click

    Click image for larger version. 

Name:	Address Box.jpg 
Views:	12 
Size:	40.1 KB 
ID:	48435

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    exactly. NO more edit hyperlink. Just edit the file path in the box. How easy.

  5. #5
    PMal is offline Novice
    Windows 11 Office 365
    Join Date
    Jul 2022
    Posts
    12
    Quote Originally Posted by ranman256 View Post
    exactly. NO more edit hyperlink. Just edit the file path in the box. How easy.

    That means me writing our full file paths for new records....even more time consuming

  6. #6
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,653
    Personally I find HyperLink datatype to be a P.I.T.A. to work with.
    Like RanMan I use a text datatype and use a similiar procedure to open it in its native program.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  7. #7
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,653
    Quote Originally Posted by PMal View Post
    That means me writing our full file paths for new records....even more time consuming
    I use either a file picker, folder picker or cut & paste for the paths. Have never typed them.

    when dealing with mapped drives in a network use the Unc path to avoid different mapping with different computers

    Code:
    Function GetUNC(strMappedDrive As String) As String
    
    
        Dim objFso As FileSystemObject
        On Error GoTo GetUNC_Error
    
    
        Set objFso = New FileSystemObject
        Dim strDrive As String
        Dim strShare As String
    
    
        'Separated the mapped letter from
        'any following sub-folders
        strDrive = objFso.GetDriveName(strMappedDrive)
    
    
        'find the UNC share name from the mapped letter
        strShare = objFso.Drives(strDrive).ShareName
    
    
        'The Replace function allows for sub-folders
        'of the mapped drive
        GetUNC = Replace(strMappedDrive, strDrive, strShare)
    
    
        Set objFso = Nothing    'Destroy the object
    
    
        On Error GoTo 0
        Exit Function
    
    
    GetUNC_Error:
    
    
        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure GetUNC of Module modAlwaysIncluded"
    
    
    End Function
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

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

Similar Threads

  1. vba for button, hyperlink error
    By mainerain in forum Forms
    Replies: 3
    Last Post: 04-14-2022, 01:47 PM
  2. Replies: 4
    Last Post: 06-17-2021, 01:32 AM
  3. Creating a Browse button to create a Hyperlink
    By detaylor1242 in forum Forms
    Replies: 5
    Last Post: 07-30-2013, 11:48 AM
  4. Add button to follow hyperlink in table
    By stanley721 in forum Forms
    Replies: 6
    Last Post: 06-22-2013, 08:49 AM
  5. Command button as a Hyperlink
    By Alaska1 in forum Access
    Replies: 3
    Last Post: 10-21-2010, 02:08 PM

Tags for this Thread

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