By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,473 Members | 3,234 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,473 IT Pros & Developers. It's quick & easy.

Display File Title, Link Using File Path

P: 55
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:

Expand|Select|Wrap|Line Numbers
  1. Private Sub FilePath_Click()
  2.     Rem Me![AutoNumber]
  3.     Dim stlink As String
  4.         stlink = Me![FilePath]
  5.         FollowHyperlink stlink, , True
  6. End Sub
Here's the related function:

Expand|Select|Wrap|Line Numbers
  1. Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
  2. "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
  3.  
  4. Private Type OPENFILENAME
  5.     lStructSize As Long
  6.     hwndOwner As Long
  7.     hInstance As Long
  8.     lpstrFilter As String
  9.     lpstrCustomFilter As String
  10.     nMaxCustFilter As Long
  11.     nFilterIndex As Long
  12.     lpstrFile As String
  13.     nMaxFile As Long
  14.     lpstrFileTitle As String
  15.     nMaxFileTitle As Long
  16.     lpstrInitialDir As String
  17.     lpstrTitle As String
  18.     flags As Long
  19.     nFileOffset As Integer
  20.     nFileExtension As Integer
  21.     lpstrDefExt As String
  22.     lCustData As Long
  23.     lpfnHook As Long
  24.     lpTemplateName As String
  25. End Type
  26.  
  27. Function LaunchCD(strform As Form) As String
  28.     Dim OpenFile As OPENFILENAME
  29.     Dim lReturn As Long
  30.     Dim sFilter As String
  31.     OpenFile.lStructSize = Len(OpenFile)
  32.     OpenFile.hwndOwner = strform.Hwnd
  33.     sFilter = "All Files (*.*)" & Chr(0) & "*.*" & Chr(0) & _
  34.       "HTM Files (*.HTM)" & Chr(0) & "*.HTM" & Chr(0) & _
  35.       "HTML Files (*.HTML)" & Chr(0) & "*.HTML" & Chr(0)
  36.     OpenFile.lpstrFilter = sFilter
  37.     OpenFile.nFilterIndex = 2
  38.     OpenFile.lpstrFile = String(257, 0)
  39.     OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
  40.     OpenFile.lpstrFileTitle = OpenFile.lpstrFile
  41.     OpenFile.nMaxFileTitle = OpenFile.nMaxFile
  42.     OpenFile.lpstrInitialDir = "H:\Application\Cables\"
  43.     OpenFile.lpstrTitle = "Select a file..."
  44.     OpenFile.flags = 0
  45.     lReturn = GetOpenFileName(OpenFile)
  46.         If lReturn = 0 Then
  47.             MsgBox "No file selected", vbInformation, _
  48.               "Please select a file"
  49.          Else
  50.             LaunchCD = Trim(Left(OpenFile.lpstrFileTitle, InStr(1, OpenFile.lpstrFileTitle, vbNullChar) - 1))
  51.          End If
  52. End Function
Can someone clue me in on how to display the FileTitle but link using the path?

Regards,
BASSPU03
Dec 14 '07 #1
Share this Question
Share on Google+
2 Replies


ADezii
Expert 5K+
P: 8,597
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:

Expand|Select|Wrap|Line Numbers
  1. Private Sub FilePath_Click()
  2.     Rem Me![AutoNumber]
  3.     Dim stlink As String
  4.         stlink = Me![FilePath]
  5.         FollowHyperlink stlink, , True
  6. End Sub
Here's the related function:

Expand|Select|Wrap|Line Numbers
  1. Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
  2. "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
  3.  
  4. Private Type OPENFILENAME
  5.     lStructSize As Long
  6.     hwndOwner As Long
  7.     hInstance As Long
  8.     lpstrFilter As String
  9.     lpstrCustomFilter As String
  10.     nMaxCustFilter As Long
  11.     nFilterIndex As Long
  12.     lpstrFile As String
  13.     nMaxFile As Long
  14.     lpstrFileTitle As String
  15.     nMaxFileTitle As Long
  16.     lpstrInitialDir As String
  17.     lpstrTitle As String
  18.     flags As Long
  19.     nFileOffset As Integer
  20.     nFileExtension As Integer
  21.     lpstrDefExt As String
  22.     lCustData As Long
  23.     lpfnHook As Long
  24.     lpTemplateName As String
  25. End Type
  26.  
  27. Function LaunchCD(strform As Form) As String
  28.     Dim OpenFile As OPENFILENAME
  29.     Dim lReturn As Long
  30.     Dim sFilter As String
  31.     OpenFile.lStructSize = Len(OpenFile)
  32.     OpenFile.hwndOwner = strform.Hwnd
  33.     sFilter = "All Files (*.*)" & Chr(0) & "*.*" & Chr(0) & _
  34.       "HTM Files (*.HTM)" & Chr(0) & "*.HTM" & Chr(0) & _
  35.       "HTML Files (*.HTML)" & Chr(0) & "*.HTML" & Chr(0)
  36.     OpenFile.lpstrFilter = sFilter
  37.     OpenFile.nFilterIndex = 2
  38.     OpenFile.lpstrFile = String(257, 0)
  39.     OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
  40.     OpenFile.lpstrFileTitle = OpenFile.lpstrFile
  41.     OpenFile.nMaxFileTitle = OpenFile.nMaxFile
  42.     OpenFile.lpstrInitialDir = "H:\Application\Cables\"
  43.     OpenFile.lpstrTitle = "Select a file..."
  44.     OpenFile.flags = 0
  45.     lReturn = GetOpenFileName(OpenFile)
  46.         If lReturn = 0 Then
  47.             MsgBox "No file selected", vbInformation, _
  48.               "Please select a file"
  49.          Else
  50.             LaunchCD = Trim(Left(OpenFile.lpstrFileTitle, InStr(1, OpenFile.lpstrFileTitle, vbNullChar) - 1))
  51.          End If
  52. End Function
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:
Expand|Select|Wrap|Line Numbers
  1. Dim strFileTitle As String, lpstrFile As String
  2.  
  3. lpstrFile = "C:\Windows\System32\My DLLs\SomeDLL.dll"
  4. strFileTitle = Right$(lpstrFile, Len(lpstrFile) - InStrRev(lpstrFile, "\"))
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. SomeDLL.dll
Me![txtFileTitle] = strFileTitle
Dec 15 '07 #2

ADezii
Expert 5K+
P: 8,597
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:
Expand|Select|Wrap|Line Numbers
  1. Dim strFileTitle As String, lpstrFile As String
  2.  
  3. lpstrFile = "C:\Windows\System32\My DLLs\SomeDLL.dll"
  4. strFileTitle = Right$(lpstrFile, Len(lpstrFile) - InStrRev(lpstrFile, "\"))
  5.  
  6. Me![txtFileTitle] = strFileTitle
  7.  
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. SomeDLL.dll
Dec 15 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.