Display File Title, Link Using File Path

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BASSPU03
    New Member
    • Oct 2007
    • 55

    #1

    Display File Title, Link Using File Path

    I used the Common Dialog API to store file paths on my form's underlying table. These paths are displayed in a textbox that I can click to open the selected file.

    Having stored the file paths in a textbox on my form, I then changed VB code in a linked module from lpstrFile to lpstrFileTitle (in Line 50 below) to get the file's title instead of the full path. Now, I'd like the file title to keep showing up in the textbox, but I obviously need the full path "underneath " so that, when I click on the file title, the file opens. I've experimented by changing different "lpstrFile" references but can't get the desired result. Here's the On Click event code:

    [CODE=vb]Private Sub FilePath_Click( )
    Rem Me![AutoNumber]
    Dim stlink As String
    stlink = Me![FilePath]
    FollowHyperlink stlink, , True
    End Sub[/CODE]

    Here's the related function:

    [CODE=vb]Private Declare Function GetOpenFileName Lib "comdlg32.d ll" Alias _
    "GetOpenFileNam eA" (pOpenfilename As OPENFILENAME) As Long

    Private Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilt er As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
    End Type

    Function LaunchCD(strfor m As Form) As String
    Dim OpenFile As OPENFILENAME
    Dim lReturn As Long
    Dim sFilter As String
    OpenFile.lStruc tSize = Len(OpenFile)
    OpenFile.hwndOw ner = strform.Hwnd
    sFilter = "All Files (*.*)" & Chr(0) & "*.*" & Chr(0) & _
    "HTM Files (*.HTM)" & Chr(0) & "*.HTM" & Chr(0) & _
    "HTML Files (*.HTML)" & Chr(0) & "*.HTML" & Chr(0)
    OpenFile.lpstrF ilter = sFilter
    OpenFile.nFilte rIndex = 2
    OpenFile.lpstrF ile = String(257, 0)
    OpenFile.nMaxFi le = Len(OpenFile.lp strFile) - 1
    OpenFile.lpstrF ileTitle = OpenFile.lpstrF ile
    OpenFile.nMaxFi leTitle = OpenFile.nMaxFi le
    OpenFile.lpstrI nitialDir = "H:\Application \Cables\"
    OpenFile.lpstrT itle = "Select a file..."
    OpenFile.flags = 0
    lReturn = GetOpenFileName (OpenFile)
    If lReturn = 0 Then
    MsgBox "No file selected", vbInformation, _
    "Please select a file"
    Else
    LaunchCD = Trim(Left(OpenF ile.lpstrFileTi tle, InStr(1, OpenFile.lpstrF ileTitle, vbNullChar) - 1))
    End If
    End Function[/CODE]

    Can someone clue me in on how to display the FileTitle but link using the path?

    Regards,
    BASSPU03
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by BASSPU03
    I used the Common Dialog API to store file paths on my form's underlying table. These paths are displayed in a textbox that I can click to open the selected file.

    Having stored the file paths in a textbox on my form, I then changed VB code in a linked module from lpstrFile to lpstrFileTitle (in Line 50 below) to get the file's title instead of the full path. Now, I'd like the file title to keep showing up in the textbox, but I obviously need the full path "underneath " so that, when I click on the file title, the file opens. I've experimented by changing different "lpstrFile" references but can't get the desired result. Here's the On Click event code:

    [CODE=vb]Private Sub FilePath_Click( )
    Rem Me![AutoNumber]
    Dim stlink As String
    stlink = Me![FilePath]
    FollowHyperlink stlink, , True
    End Sub[/CODE]

    Here's the related function:

    [CODE=vb]Private Declare Function GetOpenFileName Lib "comdlg32.d ll" Alias _
    "GetOpenFileNam eA" (pOpenfilename As OPENFILENAME) As Long

    Private Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilt er As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
    End Type

    Function LaunchCD(strfor m As Form) As String
    Dim OpenFile As OPENFILENAME
    Dim lReturn As Long
    Dim sFilter As String
    OpenFile.lStruc tSize = Len(OpenFile)
    OpenFile.hwndOw ner = strform.Hwnd
    sFilter = "All Files (*.*)" & Chr(0) & "*.*" & Chr(0) & _
    "HTM Files (*.HTM)" & Chr(0) & "*.HTM" & Chr(0) & _
    "HTML Files (*.HTML)" & Chr(0) & "*.HTML" & Chr(0)
    OpenFile.lpstrF ilter = sFilter
    OpenFile.nFilte rIndex = 2
    OpenFile.lpstrF ile = String(257, 0)
    OpenFile.nMaxFi le = Len(OpenFile.lp strFile) - 1
    OpenFile.lpstrF ileTitle = OpenFile.lpstrF ile
    OpenFile.nMaxFi leTitle = OpenFile.nMaxFi le
    OpenFile.lpstrI nitialDir = "H:\Application \Cables\"
    OpenFile.lpstrT itle = "Select a file..."
    OpenFile.flags = 0
    lReturn = GetOpenFileName (OpenFile)
    If lReturn = 0 Then
    MsgBox "No file selected", vbInformation, _
    "Please select a file"
    Else
    LaunchCD = Trim(Left(OpenF ile.lpstrFileTi tle, InStr(1, OpenFile.lpstrF ileTitle, vbNullChar) - 1))
    End If
    End Function[/CODE]

    Can someone clue me in on how to display the FileTitle but link using the path?

    Regards,
    BASSPU03
    Revert back to the lpstrFile technique to write the Absolute Path to a Bound Text Box which is invisible on the Form. It is then a simple matter to extract the File Title itself from lpstrFile and display it in another, visible Text Box. This value can either be stored internally (no reason to do so), or dynamically generated in a Query (Calculated Field) which underlies the Form, and which is displayed via the Form's Current() Event. The logic wouold be as follows:
    [CODE=vb]Dim strFileTitle As String, lpstrFile As String

    lpstrFile = "C:\Windows\Sys tem32\My DLLs\SomeDLL.dl l"
    strFileTitle = Right$(lpstrFil e, Len(lpstrFile) - InStrRev(lpstrF ile, "\"))[/CODE]
    OUTPUT:
    [CODE=text]SomeDLL.dll[/CODE]

    Me![txtFileTitle] = strFileTitle

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Revert back to the lpstrFile technique to write the Absolute Path to a Bound Text Box which is invisible on the Form. It is then a simple matter to extract the File Title itself from lpstrFile and display it in another, visible Text Box. This value can either be stored internally (no reason to do so), or dynamically generated in a Query (Calculated Field) which underlies the Form, and which is displayed via the Form's Current() Event. The logic would be as follows:
      [CODE=vb]Dim strFileTitle As String, lpstrFile As String

      lpstrFile = "C:\Windows\Sys tem32\My DLLs\SomeDLL.dl l"
      strFileTitle = Right$(lpstrFil e, Len(lpstrFile) - InStrRev(lpstrF ile, "\"))

      Me![txtFileTitle] = strFileTitle
      [/CODE]
      OUTPUT:
      [CODE=text]SomeDLL.dll[/CODE]

      Comment

      Working...