Browse Hard Drive in MS Access Form

  • Thread starter Thread starter yisraelharris
  • Start date Start date
Y

yisraelharris

I am building a MS Access form. In one of the fields, I want the user t
specify a file on the hard drive, to be used later. How do I set th
field up to allow the user to browse through the folders of the har
drive, and select the desired file, so that the complete path nam
appears in the field, without the need for the user to type in th
entire path name?

[In other words, I wish to implement in MS Access the equivalent of a
input type=file in html.]

I have seen Ken Getz's solutio
(http://www.mvps.org/access/api/api0001.htm), but, as I am a novice i
MS Access, I don't know how to use it. Also, I wonder if it provide
more functionality than I need. (I don't need the ability to open/save
just select a file.)

Since I am a novice in MS Access, solutions which are more detailed an
assume very little will be most helpful. Thank you
 
yisraelharris said:
I am building a MS Access form. In one of the fields, I want the user to
specify a file on the hard drive, to be used later. How do I set the
field up to allow the user to browse through the folders of the hard
drive, and select the desired file, so that the complete path name
appears in the field, without the need for the user to type in the
entire path name?

[In other words, I wish to implement in MS Access the equivalent of an
input type=file in html.]

I have seen Ken Getz's solution
(http://www.mvps.org/access/api/api0001.htm), but, as I am a novice in
MS Access, I don't know how to use it. Also, I wonder if it provides
more functionality than I need. (I don't need the ability to open/save,
just select a file.)

Since I am a novice in MS Access, solutions which are more detailed and
assume very little will be most helpful. Thank you.
My example is some of the code I use in a restore routine to restore the
tables to an Access database
from a backup database. Take all of the code from the API0001.htm file
and put it in a standard
module. Click th emodule tab, click New, paste the code in and close r
save the module.
The routine you are going to call is GetOpenFile(Parm1, Parm2).

In the function statement, you are passing the path for the open dialog
to start from
and the title of the dialog box when it opens. If you just do a
File/Open or File/Save
in Word, Excel, Paint, or Access and study the dialog box, you will see
what is going on.
You could make the title "Select File".
If you know the directory the file(s) is in, then you can give the
directory in the path like
"C:\SomeDirectory\".

In the code you copied, you will need to change this line so that it
matches the file type and
extension you want.
strFilter = ahtAddFilterItem(strFilter, _
"Access (*.mdb)", "*.MDB;*.MDA")

So if you are working with text files, you would code something like this.

strFilter = ahtAddFilterItem(strFilter, "Text (*.TXT)")


If the function works correctly, it will return the file name selected.
At that point you
can save it.

Me!txtFileName = cOpenFileName
or
rs!FileName = cOpenFileName

If it doesn't return correctly because the user clicked Open without
selecting a file
or they clicked cancel, then you can display an error message and exit
the function.
I have this code in a click event of a button.

example:
---------------------------------------
Dim cOpenFileName As Variant
Dim cPath As String


cPath="C:\"
or
cPath= "C:\SomeDirectory\"

cOpenFileName = GetOpenFile(cPath, "Open")
If cOpenFileName = "" Or IsNull(cOpenFileName) Or IsEmpty(cOpenFileName)
Then
MsgTitle = "Input Error"
MsgLine1 = "You must select a file to restore."
MsgDialog = MB_ICONSTOP + MB_DEFBUTTON1
MsgAnswer = MsgBox(MsgLine1, MsgDialog, MsgTitle)
Exit Sub
End If

Ron
--

Ronald W. Roberts
Roberts Communication
(e-mail address removed)
To reply remove "_at_robcom_dot_com"
 
Back
Top