Results 1 to 4 of 4
  1. #1
    RayMilhon is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085

    Hyperlink question


    I have a database I'm building the Backend will be SQL Server 2012 the front end will be MS Access 2010. One of the fields in SQL Server will be a varchar(100) field which will contain the path to a file Such as \\Server1\Contracts\VMMS1234.pdf

    What I'm looking to do is when the user clicks on that field the pdf file will open. If the field is empty the user will be prompted to locate the correct file to place in that field. I just have no clue how to proceed. Anybody know where I can look up this information or point me in the direction of accomplishing this?

    Thanks in advance

  2. #2
    nhorton79 is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Apr 2015
    Posts
    34
    I have a User defined function and some vba that I've used in my database. I'll track it down and post it here soon

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    See if this helps:

    Code:
      If Me.txtAttachment = "None" Or Len(Me.txtAttachment & vbNullString) = 0 Then
    
        strFilter = ""  'ahtAddFilterItem(strFilter, "Excel Files (*.XLS)", "*.XLS")
        strInputFileName = ahtCommonFileOpenSave(InitialDir:="Path for default here", _
                                                 Filter:=strFilter, OpenFile:=True, _
                                                 DialogTitle:="Please select an input file...", _
                                                 Flags:=ahtOFN_HIDEREADONLY)
    
        Me.txtAttachment = strInputFileName
      Else
        'Application.FollowHyperlink Me.txtAttachment
        Dim objshell              As Object
        Set objshell = CreateObject("Shell.application")
        objshell.Shellexecute Me.txtAttachment, , , , 1
      End If
    http://access.mvps.org/access/api/api0001.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    nhorton79 is offline Advanced Beginner
    Windows 8 Access 2007
    Join Date
    Apr 2015
    Posts
    34
    Well, looks like pbaldy beat me to it...but here it is anyway.

    Code:
    Private Sub txtAttachmentPath_DblClick(Cancel As Integer)
     
    Dim strFile As String
    strFile = Me.txtAttachment
     
    If Len(Dir(strFile, vbDirectory)) = 0 Then
        Dim dlgOpen As FileDialog
        Set dlgOpen = Application.FileDialog(msoFileDialogOpen)
        With dlgOpen
        .AllowMultiSelect = False
        .InitialFileName = "C:\" 'Initial Path when explorer is opened
        .Show
            If .SelectedItems.Count = 0 Then
                MsgBox "No file selected"              'No folder selected
            Else
                Me.txtAttachment = .SelectedItems(1)
            End If
        End With
    Else
        X = fHandleFile(strFile, WIN_NORMAL)
    End If
    End Sub
    You will also need to create a user defined function: Alt+F11 > Insert Module then paste the below code into module:

    Code:
    Option Compare Database
     
    '************ Code Start **********
    ' This code was originally written by Dev Ashish.
    ' It is not to be altered or distributed,
    ' except as part of an application.
    ' You are free to use it in any application,
    ' provided the copyright notice is left unchanged.
    '
    ' Code Courtesy of
    ' Dev Ashish
    '
    #If VBA7 Then    ' VBA7
    Private Declare PtrSafe Function apiShellExecute Lib "shell32.dll" _
        Alias "ShellExecuteA" _
        (ByVal hwnd As LongPtr, _
        ByVal lpOperation As String, _
        ByVal lpFile As String, _
        ByVal lpParameters As String, _
        ByVal lpDirectory As String, _
        ByVal nShowCmd As LongPtr) _
        As Long
     
    #Else    ' Downlevel when using previous version of VBA7
     
    Private Declare Function apiShellExecute Lib "shell32.dll" _
        Alias "ShellExecuteA" _
        (ByVal hwnd As Long, _
        ByVal lpOperation As String, _
        ByVal lpFile As String, _
        ByVal lpParameters As String, _
        ByVal lpDirectory As String, _
        ByVal nShowCmd As Long) _
        As Long
     
    #End If
     
     
    '***App Window Constants***
    Public Const WIN_NORMAL = 1         'Open Normal
    Public Const WIN_MAX = 3            'Open Maximized
    Public Const WIN_MIN = 2            'Open Minimized
     
    '***Error Codes***
    Private Const ERROR_SUCCESS = 32&
    Private Const ERROR_NO_ASSOC = 31&
    Private Const ERROR_OUT_OF_MEM = 0&
    Private Const ERROR_FILE_NOT_FOUND = 2&
    Private Const ERROR_PATH_NOT_FOUND = 3&
    Private Const ERROR_BAD_FORMAT = 11&
     
    '***************Usage Examples***********************
    'Open a folder:     ?fHandleFile("C:\TEMP\",WIN_NORMAL)
    'Call Email app:    ?fHandleFile("mailto:dash10@hotmail.com",WIN_NORMAL)
    'Open URL:          ?fHandleFile("http://home.att.net/~dashish", WIN_NORMAL)
    'Handle Unknown extensions (call Open With Dialog):
    '                   ?fHandleFile("C:\TEMP\TestThis",Win_Normal)
    'Start Access instance:
    '                   ?fHandleFile("I:\mdbs\CodeNStuff.mdb", Win_NORMAL)
    '****************************************************
     
    Function fHandleFile(stFile As String, lShowHow As Long)
    Dim lRet As Long, varTaskID As Variant
    Dim stRet As String
        'First try ShellExecute
        lRet = apiShellExecute(hWndAccessApp, vbNullString, _
                stFile, vbNullString, vbNullString, lShowHow)
               
        If lRet > ERROR_SUCCESS Then
            stRet = vbNullString
            lRet = -1
        Else
            Select Case lRet
                Case ERROR_NO_ASSOC:
                    'Try the OpenWith dialog
                    varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
                            & stFile, WIN_NORMAL)
                    lRet = (varTaskID <> 0)
                Case ERROR_OUT_OF_MEM:
                    stRet = "Error: Out of Memory/Resources. Couldn't Execute!"
                Case ERROR_FILE_NOT_FOUND:
                    stRet = "Error: File not found.  Couldn't Execute!"
                Case ERROR_PATH_NOT_FOUND:
                    stRet = "Error: Path not found. Couldn't Execute!"
                Case ERROR_BAD_FORMAT:
                    stRet = "Error:  Bad File Format. Couldn't Execute!"
                Case Else:
            End Select
        End If
        fHandleFile = lRet & _
                    IIf(stRet = "", vbNullString, ", " & stRet)
    End Function
    '************ Code End **********
    This might be more convoluted that pbaldy's but its worked for me.

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

Similar Threads

  1. Hyperlink in forms Question
    By johnnyBQue in forum Forms
    Replies: 4
    Last Post: 12-02-2014, 07:59 AM
  2. Very Newb question on hyperlink
    By skim464 in forum Access
    Replies: 1
    Last Post: 04-01-2014, 09:20 AM
  3. Replies: 4
    Last Post: 01-05-2013, 11:07 AM
  4. Hyperlink Question
    By bmschaeffer in forum Reports
    Replies: 1
    Last Post: 10-20-2011, 03:33 PM
  5. Replies: 4
    Last Post: 01-31-2011, 03:19 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