Results 1 to 2 of 2
  1. #1
    ccordner is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    65

    Hyperlinks (UNC)

    Hi

    I have some code (reproduced below) from a button in Excel which opens the 'Browse' button for the user to select a file, it then puts a link to that file in the cell, using the UNC path.



    How do I adapt this to work for Access?

    I want to store a link to a file in a table.

    Thanks
    Chris

    P.S. Ideally, the full link wouldn't show, only the document name.

    Code:
    ' The size used for the string buffer. Adjust this if you
    ' need a larger buffer.
    Const lBUFFER_SIZE As Long = 255
    Dim Filter As String, Title As String
    Dim FilterIndex As Integer
    Dim FileName, NewFileName As Variant
    Sub Button2_Click()
    If Not ActiveCell.Column = 7 Then
        Exit Sub
        ElseIf ActiveCell.Row < 4 Then
        Exit Sub
        ElseIf ActiveCell.Row > 203 Then
        Exit Sub
    End If
    Filter = "View All Files (*.*),*.*," & _
        "Microsoft Excel Spreadsheet (*.xls),*.xls," & _
        "Microsoft Word Document (*.doc),*.doc,"
    FilterIndex = 3
    Title = "Select a File to Open"
    With Application
        FileName = .GetOpenFilename(Filter, FilterIndex, Title)
    End With
    If FileName = False Then
        Exit Sub
        Else
        
        ' Trim the filename to find the mapped drive letter.
        DriveLetter = Left(FileName, 1) & ":"
        ' Specifies the size in characters of the buffer.
        cbRemoteName = lBUFFER_SIZE
        ' Prepare a string variable by padding spaces.
        lpszRemoteName = lpszRemoteName & Space(lBUFFER_SIZE)
        ' Return the UNC path (\\Server\Share).
        lstatus& = WNetGetConnection32(DriveLetter, lpszRemoteName, _
        cbRemoteName)
        ' Verify that the WNetGetConnection() succeeded. WNetGetConnection()
        ' returns 0 (NO_ERROR) if it successfully retrieves the UNC path.
        If lstatus& = NO_ERROR Then
        
            'Add UNC path to beginning of FileName
            NewFileName = Left(Trim(lpszRemoteName), (Len(Trim(lpszRemoteName)) - 1)) & "\" & Right(FileName, (Len(FileName) - 3))
            Else
            
            MsgBox ("An error has occurred with" & Chr(10) & lstatus& & Chr(10) & "Please contact C Cordner. This device will self-destruct in thirty seconds")
            Exit Sub
        End If
        'Copy FileName to ActiveCell
        ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=NewFileName, SubAddress:= _
        "", TextToDisplay:=Right(NewFileName, (Len(NewFileName) - InStrRev(NewFileName, "\")))
    End If

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. button hyperlinks
    By nichmeg in forum Forms
    Replies: 14
    Last Post: 01-28-2014, 03:09 PM
  2. Using Hyperlinks in Listbox
    By michaelb in forum Forms
    Replies: 1
    Last Post: 11-09-2011, 03:21 PM
  3. Help with embedding Hyperlinks!
    By adrian84 in forum Access
    Replies: 2
    Last Post: 06-21-2011, 01:25 PM
  4. Help with hyperlinks
    By dumbFounded in forum Access
    Replies: 4
    Last Post: 04-26-2011, 01:40 PM
  5. Hyperlinks
    By Issy in forum Access
    Replies: 0
    Last Post: 11-13-2007, 04:46 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