Extracting file path and name

A

Apples76

i have foud the following code on the access web and want to extract the file
name and path which is output to the msgbox. can anybody help extract the
variable to be saved in a control.

i have attached the event to the onclick event which triggers the file
search but does not save the variable for later use.

Function TestIt()
Dim strFilter As String
Dim lngFlags As Long
Dim FleNme As String

strFilter = ahtAddFilterItem(strFilter, "Access Files (*.mda, *.mdb)", _
"*.MDA;*.MDB")
strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)", "*.DBF")
strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.TXT")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
MsgBox "You selected: " & ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Hello! Open Me!")
FleNme = lngFlags

' Since you passed in a variable for lngFlags,
' the function places the output flags value in the variable.
Debug.Print Hex(lngFlags)
End Function
 
D

Douglas J. Steele

Function TestIt()
Dim strFilter As String
Dim lngFlags As Long
Dim FleNme As String

strFilter = ahtAddFilterItem(strFilter, "Access Files (*.mda, *.mdb)", _
"*.MDA;*.MDB")
strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)", "*.DBF")
strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.TXT")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
FleNme = ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Hello! Open Me!")
FleNme = lngFlags
MsgBox "You selected: " & FleNme

' Since you passed in a variable for lngFlags,
' the function places the output flags value in the variable.
Debug.Print Hex(lngFlags)
End Function
 
D

Daniel

ahtCommonFileOpenSave(InitialDir:="C:\", _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Hello! Open Me!")

Returns the filename/path of the file selected by the users.

Use can use the Dir Function to extract the filename from the full path.

So your best bet is to set the ahtCommonFileOpenSave(...) to a variable and
then manipulate the variable as required.

Here's a sample I use for images.

Dim strFilter As String
Dim lngFlags As Long
Dim Docpath, FileName, StartDir, driveletter As String

strFilter = ahtAddFilterItem(strFilter, "Images Files",
"*.gif;*.jpeg;*.jpg;*.bmp;*.tif")
StartDir = "c:\"
Docpath = ahtCommonFileOpenSave(InitialDir:=StartDir,
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, DialogTitle:="Select
Document")

If Not Docpath = "" Then
FileName = Dir(Docpath)
Me.imgPath = Docpath
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top