473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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:

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
2 4518
ADezii
8,834 Expert 8TB
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
8,834 Expert 8TB
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

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

Similar topics

7
by: moondaddy | last post by:
I want to dynamically create a JavaScript file and cache it on the client for re-use. I know how to write javascript to a web page from the code behind, but I don't know how to actually create a...
7
by: TLM | last post by:
I am trying to build a web application that will contain links to files on a users local computer. I am assuming that the files will be in a known location and can display in a browser window. ...
1
by: shapper | last post by:
Hello, I have a XMl file with the following format: <?xml version="1.0" encoding="utf-8" ?> <siteMap xmlns = "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" > <siteMapNode>...
7
by: ApexData | last post by:
Hello I currently Link the FE/BE using the LinkTables Option and the Linked Table Manager. Any time I need to move the BE to another location, I have to go through this process over again. I...
11
by: Jankie | last post by:
I need to dispaly a user's multiple images in one entry.Right now,say if a user uploads 3 images,three entries for the same id display to match 3 images. I only want 1 entry to display all of a...
2
by: smorrison64 | last post by:
I have a form that is coded to open a File Dialog boc to pick a picture to display on that particular item on a subform. My form is not based on query, but rather two separate tables (one primary,...
2
by: amritranjan | last post by:
This is my Jsp code for image upload in database: -----------Upload.jsp---------------- <html> <head> <title>Account Details </title> </head> <body bgproperties="fixed" bgcolor="#CCFFFF">...
2
by: Tim Streater | last post by:
The following test page is intended to allow the user to choose an image file, and then display it. It works as expected in Safari 3.1.1, FF 2.0.0.14 (Mac), and IE7 (XP). But, it fails in FF...
3
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.