How to get a file name by browsing a specific folder

N

Nuno Guerra

Hi! First off all congratulations for you all by make this discussion group
so helpfull.

I would like to add a button in my form to open a dialog box, browse a
specific folder, choose any file and then change the value of a text box in
my form with the filename I had choosed in the browser.

I have a text box that will be populate with the filename I choosed from the
browser.

I saw the Georgie's thread on 10/5/2005 but I don't know
if the solutions presented are the same for my question.
 
D

Douglas J Steele

Take a look at http://www.mvps.org/access/api/api0001.htm

The 4 line example at the start of the page shows how you'd get the filename
in a variable using the code on the rest of the page:

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)

Once you've got the filename in a variable, you can plug that value into a
text box using code like:

Me.txtFilename = strInputFileName

(where txtFilename is the name of a text box on your form)
 
N

Nuno Guerra

Thanks a lot. It works!!

I would like to ask just a last question:
For default, this code browses a window in "My Documents". How can I
pre-define a specific location by default?

Thanks again.
 
N

Nuno Guerra

Douglas, I think I just found it:
Is in ahtCommonFileOpenSave Function.

I have to change this line "If IsMissing(InitialDir) Then InitialDir = CurDir"
and change the CurDir Value for the folder's name string, am I correct?
 
D

Douglas J Steele

Actually, it's even simpler than that.

You simply have to pass a value for InitialDir when you call the function.

Take a look at the function GetOpenFile that's defined in the stuff you
copied from that page. It shows using that parameter.
 

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