A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

common dialogue box to save file path



 
 
Thread Tools Display Modes
  #1  
Old July 6th, 2009, 09:37 PM posted to microsoft.public.access
kbob
external usenet poster
 
Posts: 5
Default common dialogue box to save file path

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
  #2  
Old July 6th, 2009, 10:06 PM posted to microsoft.public.access
Albert D. Kallal
external usenet poster
 
Posts: 2,874
Default common dialogue box to save file path

"kbob" wrote in message
...

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 he

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

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

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada




Note that runtime also works..


  #3  
Old July 6th, 2009, 10:54 PM posted to microsoft.public.access
kbob
external usenet poster
 
Posts: 5
Default common dialogue box to save file path

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

"Albert D. Kallal" wrote:

"kbob" wrote in message
...

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 he

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

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

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada




Note that runtime also works..



  #4  
Old July 7th, 2009, 12:25 AM posted to microsoft.public.access
Albert D. Kallal
external usenet poster
 
Posts: 2,874
Default common dialogue box to save file path

"kbob" wrote in message
news
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)

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada



  #5  
Old July 7th, 2009, 05:34 PM posted to microsoft.public.access
kbob
external usenet poster
 
Posts: 5
Default common dialogue box to save file path

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?

"Albert D. Kallal" wrote:

"kbob" wrote in message
news
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)

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada




  #6  
Old July 7th, 2009, 06:00 PM posted to microsoft.public.access
Albert D. Kallal
external usenet poster
 
Posts: 2,874
Default common dialogue box to save file path

"kbob" wrote in message
...
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.


--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:42 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.