common dialogue box to save file path

K

kbob

Is there a way to have a button that on click will open a dialogue box that
allows the user to browse the computer for the file. then when the file is
selected the file path would be saved on the form in a bound text box. Then
have another button to open the file. This way a user could link a record to
a file and view the file from the same form
 
A

Albert D. Kallal

Is there a way to have a button that on click will open a dialogue box
that
allows the user to browse the computer for the file. then when the file is
selected the file path would be saved on the form in a bound text box.
Then
have another button to open the file. This way a user could link a record
to
a file and view the file from the same form

To pop open the file dilaog

Dim f As FileDialog
Set f = Application.FileDialog(msoFileDialogFilePicker)
f.Show
MsgBox "file choose was " & f.SelectedItems(1)

So, to suff the results into a text box go:

me.MyPathNameTextBox = f.SelectedItems(1)

You can late bind if you wish:

above needs: Microsoft Object 11.0 Object library

If you remove the reference to the 11.0 object library, then the following
code will work without any references:


Dim f As Object
Set f = Application.FileDialog(3)
f.AllowMultiSelect = True
f.Show

MsgBox "file choosen = " & f.SelectedItems.Count

to Launch the file in the above text box then go:

Application.FollowHyperlink me.MyPathNameTextBox

the above filedialog feature was added to access 2002, or 2003. If you have
eailer version then you have to use the file open dialog api here:

http://www.mvps.org/access/api/api0001.htm

Folder browse here:
http://www.mvps.org/access/api/api0002.htm

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
(e-mail address removed)



Note that runtime also works..
 
K

kbob

i pasted the code but when I click the button nothing happens. did i miss
something?
 
A

Albert D. Kallal

kbob said:
i pasted the code but when I click the button nothing happens. did i miss
something?

Try testing/placing the code behind the event code (click) for a button on
the form.

Dim f As FileDialog
Set f = Application.FileDialog(msoFileDialogFilePicker)
f.Show
MsgBox "file choose was " & f.SelectedItems(1)

After you paste in the code, then do a debug->compile ( I sure you always
done this anyway).

So, once the code compiles, then try clicking on the button. It should
display in a msgbox the file you just chosen.

It is assumed that you have other code and buttons also working and running
code in this application...correct?
(I mean if no code runs anywhere in your application, then this code not
going to work...is it?)

Also as mentioned, the filedialog was only added in access 2002, or 2003 (I
can't remember...but using debug->compile above will tell us if this code
will work for you). (it would help if you mentioned what version of access
you are using....).

Also, if above does not work, then try:

Dim f As Object
Set f = Application.FileDialog(3)
f.AllowMultiSelect = True
f.Show

MsgBox "file choosen = " & f.SelectedItems(1)
 
K

kbob

Yes it works now! Thanks! but now I am trying to get the selected file's path
to automatically be filled in a text box. Is that possible?
 
A

Albert D. Kallal

kbob said:
Yes it works now! Thanks! but now I am trying to get the selected file's
path
to automatically be filled in a text box. Is that possible?

Yes, you can use:


me.TextBoxName = f.SelectedItems(1)

So, in place of msgbox, use above.

I mean, if I go:

dim strTest as string


strTest = "hello"

Msgbox strText

The above will display a msgbox with hello.

However, if you want to stuff that into a text box, and not display it, then
go:

me.MyTextBoxName = strTest

The text box will now have the word hello.
 

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