Results 1 to 5 of 5
  1. #1
    tolga ozdemir is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Apr 2020
    Posts
    2

    how do I hyperlink in access between not same field name and pdf file name

    .Dear All,

    I have some pdf files and I want to link hem with a field in access. I found a code like below for this link and it is work.

    Private Sub DokumanNumarasi_Click()


    Application.FollowHyperlink "C:\PDF" & Me.DokumanNumarasi & ".pdf"


    End Sub


    but pdf file name more longer than dokumannumarasi. pdf file name is Y112019000005903_SelÁuk-Ecza-Dep.-Tic.-ve-San.-A.Ş..pdf and dokumannumarasi is only Y112019000005903

    My question is how I can hyperlink first 16 charactrers of PDF file name with Dokumannumarasi and it is always 16 characters.

    Could you please help me how can I write or add this in my code.

    Many thanks

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    8,837
    no need to hyper link, you can use the code below to just Open the file. (same as a hyperlink) but this works for ANY file.

    paste this code into a module. (Alt-F11, insert , module)
    Then it will open ANY file via its extension....
    .pdf files will open in acrobat,
    .doc files in word
    etc

    USAGE:
    OpenNativeApp "c:\folder\file.xls"
    'opens in excel
    or
    OpenNativeApp field
    'opens item in field in native app

    Code:
    Option Compare Database
    Option Explicit
    Code:
    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
    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
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    8,771
    You want to display part of a long string as a hyperlink? Then concatenating # with Left(your string variable here,16) could do that. Setting Display as Hyperlink to 'always' will format it as a hyperlink but it wont' work. Setting Is Hyperlink to Yes will force it to act as a hyperlink but will error because the path is wrong. I know of no way to trap that error.

    There is a Hyperlink Target property that I've never played with. Perhaps you can have two textboxes? Hide the bound one with the real path. Populate visible one with an expression using Left function to show the first 16 characters. In it, set the properties I mentioned above. Use vba to set the target property of the visible textbox. Then maybe when you click it, it won't error and will use the hyperlink target property.

    Before trying any of that I think I would research the hyperlink target property to see how it can be used because my idea is just a guess.
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    Iím telling everyone it's good to eat dried grapes. Itís all about raisin awareness.

  4. #4
    tolga ozdemir is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Apr 2020
    Posts
    2
    hi ranman256 and micron

    first of all many thanks for your support,

    actually I want to create this link as hyperlink and there is some pdf file where is in C:\Pdf and I have a field in the access form which is showing PDF file names. field name in access is equal to first 16 charecter of pdf file name under the C:\pdf\. my question which code should be included in my code below?

    Private Sub DokumanNumarasi_Click()


    Application.FollowHyperlink "C:\PDF" & Me.DokumanNumarasi & ".pdf"


    End Sub

    many thanks,

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    8,771
    I'm not sure I understand your posts. If you want to follow a hyperlink in Access, as far as I know it must be a valid path or url. If you want to show only part of a long link and still be able to use it, I'm saying I don't know how. I can only suggest you play with some of the things I mentioned or find another way. One might be to select the shortened link from a listbox and in code, use not the column value being shown but one that holds the real path/url. Then use either a double click on the listbox value or provide a button to follow the link based on the chosen short link version.
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    Iím telling everyone it's good to eat dried grapes. Itís all about raisin awareness.

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

Similar Threads

  1. Replies: 3
    Last Post: 09-16-2019, 08:11 AM
  2. About Hyperlink-File path problems
    By notrino in forum Forms
    Replies: 1
    Last Post: 10-03-2018, 11:22 AM
  3. Hyperlink file create date
    By markjkubicki in forum Access
    Replies: 1
    Last Post: 05-16-2017, 11:07 AM
  4. Hyperlink to file in text box not opening
    By timesscript in forum Forms
    Replies: 4
    Last Post: 05-18-2015, 07:06 AM
  5. Creating a hyperlink to open a pdf file
    By Jrw76 in forum Access
    Replies: 10
    Last Post: 01-24-2014, 09:42 AM

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 - Senior Forums