tool for finding paths to files

R

Ray Wallace

The users of my form need to define the location of a file they were working
on. Instead of typing or pasting the path and filename into a text control.
I want them to have the choice of clicking a browse button to define that
path. Is there some sort of control out there that can do this

Ray
 
R

Roger Carlson

If you look here: http://www.mvps.org/access/api/api0001.htm, you'll find a
method of calling the Windows File Open/Save dialog box.

On my website (www.rogersaccesslibrary.com), is a small Access database
sample called "PictureLoad.mdb" which uses this method to load the path of a
file into a field in a table. Another sample (SetHyperlink.mdb) uses this
method to store the path to a file in a table as a hyperlink.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
R

Ray Wallace

Roger,
That looks exactly like what I am looking for. however, I am so new at this
that I don't have know to implement it. Would you mind explaining.

I really appreciate you help. THANKS.
-Ray
 
D

Douglas J Steele

Copy everything between Code Start and Code End into a new module.

Save the module (make sure you don't name the module the same as any of the
routines within it. Calling it something like mdlFileDialog will be safe)

Use the sample at the top as an example of how to use it:

Dim strFilter As String
Dim strInputFileName as string

strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.XLS)", "*.XLS")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)
This will prompt the use to select an Excel file. Once they've selected the
file, the full path to it will be saved in strInputFileName. If you want to
be able to search for other file types, make additional calls to
ahtAddFilterItem:

strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.XLS)", "*.XLS")
strFilter = ahtAddFilterItem(strFilter, "Text Files (*.TXT)", "*.TXT")
strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")
 
R

Roger Carlson

Well, that's a rather tall order. One of the reasons I created the sample
databases is so you can pull them apart to see how they work. Nevertheless,
let me give you some background and then you can ask specific questions.

First, Import the module "modOpenSaveFile" into your application. Don't
make any changes to it.

Now, the way the thing works, is you call the "ahtCommonFileOpenSave"
function with the appropriate arguments and it returns a string that holds
the path and filename of the file you selected in the dialog box.

So in my PictureLoad sample, the call is behind the "Choose a Picture"
Button. The important part of the event procedure is this:

Dim strFilter As String
Dim lngFlags As Long
strFilter = ahtAddFilterItem(strFilter, "Picture Formats (*.jpg *.jpeg,
*.bmp, *.gif)", "*.jpg; *.jpeg; *.bmp; *.gif")
'MsgBox "You selected: " &
Filename = ahtCommonFileOpenSave(InitialDir:=pathname, _
Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
DialogTitle:="Select Picture File")
'display picture
Me.txtStockGraph = Filename
Me.ImgStock.Picture = Filename

AS you can see, I'm calling the "ahtCommonFileOpenSave" function and
assigning the value to the variable "Filename". Then I assign the Filename
to a textbox on the form, which is how it gets entered into the table.
Exactly what YOU will do with Filename depends on your application.

You will also see that I assign a value to the variable strFilter. For the
PictureLoad sample, I only want to load picture formats. But you can change
this to include other file formats or ALL file formats. In the
"SetHyperlink" sample, I do this:

strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")

I hope this helps you get started.


--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 

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

Top