Opening files from within access

Q

querykitty

I would like to create a button which will open a windows browser to a
specific folder and allow the user to select a text file and to be able to
view the file. I know I can link to a specific text file but need for the
user to be able to select the specific file they need. Is this possible?
Thanks.
 
T

Tom van Stiphout

On Fri, 26 Dec 2008 09:30:01 -0800, querykitty

File/Open dialog is discussed here:
http://www.mvps.org/access/api/api0001.htm

Once the user selects a file, you can use Notepad to display it. You
can use the Shell command to launch notepad.exe followed by your
filename.

-Tom.
Microsoft Access MVP
 
Q

querykitty

Hi Tom,

I've successfullly added the code for opening the browser window but when I
select the file to open nothing happens. I think you reference what I need
to do below but am not sure how to execute it.
Once the user selects a file, you can use Notepad to display it. You
can use the Shell command to launch notepad.exe followed by your
filename.

How do I get the file name the user selects to open in Notepad?

Thanks.
 
Q

querykitty

Hi Steve,

I haven't heard back from Tom on this one. I have been successful in
getting the browser form to open to the correct folder, but when I select a
file and click the open button the window closes and nothing happens. I am
not sure where/how I am supposed to put code to indicate which file to open
and in the specific application. Tom I think made reference to this but I
was not sure how to apply.

Thanks.
 
Q

querykitty

Tom & Steve Thank you. I finally got it to work. I found the "Start an app
with ShellExecute" on the same site and was able to pass the variable over
and get it to open. I called where the TestIt() function had their message
box.

Took me way to long to finger out :)
 
J

John Spencer (MVP)

The browser function will return the full path of the file selected. You need
to grab that path and store it in a variable. So you would need something
like the following if you were going to use the Shell command.

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

IF Len(StrInputFileName) > 0 then
Shell "C:\WINDOWS\SYSTEM32\notepad.exe " & _
Chr(34) & StrInputFileName & Chr(34)
End if

You will have to determine the location of NotePad.exe

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
Top