Browsing for file name

J

John F

I am using a text field called [txtPath] to store a file name.
Then I used an “ImageBox†with a control source “=[CurrentProject].[Path] &
"\Images\" & [txtPath]†this works all fine and dandy. It displays the image
in the form just like I want. I can type another file name and the view
changes to the new file.

Now I am stuck! How can I under program control browse for the file name
that I want to show up in the image box? All files are images with jpg
extension.
 
P

PieterLinden via AccessMonster.com

John said:
I am using a text field called [txtPath] to store a file name.
Then I used an “ImageBox†with a control source “=[CurrentProject].[Path] &
"\Images\" & [txtPath]†this works all fine and dandy. It displays the image
in the form just like I want. I can type another file name and the view
changes to the new file.

Now I am stuck! How can I under program control browse for the file name
that I want to show up in the image box? All files are images with jpg
extension.

use the OpenSaveFile API to prompt the user for it....
http://www.mvps.org/access/api/api0001.htm
 
J

John F

Now I am really lost???????

PieterLinden via AccessMonster.com said:
John said:
I am using a text field called [txtPath] to store a file name.
Then I used an “ImageBox†with a control source “=[CurrentProject].[Path] &
"\Images\" & [txtPath]†this works all fine and dandy. It displays the image
in the form just like I want. I can type another file name and the view
changes to the new file.

Now I am stuck! How can I under program control browse for the file name
that I want to show up in the image box? All files are images with jpg
extension.

use the OpenSaveFile API to prompt the user for it....
http://www.mvps.org/access/api/api0001.htm

--



.
 
P

PieterLinden via AccessMonster.com

John said:
Now I am really lost???????
I am using a text field called [txtPath] to store a file name.
Then I used an “ImageBox†with a control source “=[CurrentProject].[Path] &
[quoted text clipped - 8 lines]
use the OpenSaveFile API to prompt the user for it....
http://www.mvps.org/access/api/api0001.htm

You said:
How can I under program control browse for the file name
that I want to show up in the image box? All files are images with jpg
extension.

So I told you. Basically, you have to use the OpenSaveFile API. There are
examples here:
http://www.mvps.org/access/api/api0001.htm

And another one here that's a little more flexible...
http://www.lebans.com/DownloadFiles/A2KCallBackBrowseVer4.zip

The problem is that you inadvertently asked a question with a complex answer.
And it *requires* that you understand VBA.

I modified the code on his form so that it prompts for JPG files...

Private Sub cmdOpenJPGs_Click()
Dim strFilter As String
Dim strInputFileName As String

strFilter = ahtAddFilterItem(strFilter, "JPG Files (*.JPG)", "*.JPG")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select a graphic file...", _
Flags:=ahtOFN_HIDEREADONLY)

Me.Text1 = strInputFileName

End Sub

you will need to add other filters if you want PNG files or GIF files, for
example...

Private Sub cmdPromptForImageFiles_Click()
Dim strFilter As String
Dim strInputFileName As String

strFilter = ahtAddFilterItem(strFilter, "JPG Files (*.JPG)", "*.JPG")
' I added these later...
strFilter = ahtAddFilterItem(strFilter, "GIF Files (*.GIF)", "*.GIF")
strFilter = ahtAddFilterItem(strFilter, "PNG Files (*.PNG)", "*.PNG")

strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select a graphic file...", _
Flags:=ahtOFN_HIDEREADONLY)

'assign the returned file to a textbox on my form.
Me.Text1 = strInputFileName

End Sub
 

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