Open File dialog in VBA

Hi,

I want to have a user in an Access 2000 application to select a file on the hard disk. For this purpose, I'd like to use the standard Windows "open file" dialog. I seem to recall some method in VB 5 that sounded like OpenFileDialog or so, but can't find anything like it in VBA. Where should I look?
thanks
TomdpAsked:
Who is Participating?
 
dtomynConnect With a Mentor Commented:
The best and most reliable way to do this is via an API call.  The code to do this can be seen at: http://www.mvps.org/access/index.htm
 ... under the API section (it is the first one listed)

0
 
tkuppinenCommented:
You need to add a common dialog control.  This will give you access to the open file dialog box.
0
 
TomdpAuthor Commented:
Well, that's exactly the problem. I referenced "windows common controls" but don't see any file dialog box or so available. I'm looking for some code, really :)
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
believerCommented:
Check out this previously asked question.

"Free OCX Controls" - http://www.experts-exchange.com/jsp/qShow.jsp?ta=msaccess&qid=10216659 
0
 
tkuppinenCommented:
Sorry, I guess I was thinking of the VB way to do this.  Why is it so much harder to use windows controls in Access?
0
 
tomk120999Commented:
Tomdb, 2000 has changed a mite, but not much, from '97.

The method (in VBA) you need is RunCommand of the DoCmd object.  Here's what Help says:

You can use the RunCommand action to run a built-in Microsoft Access command. The command may appear on a Microsoft Access menu bar, toolbar, or shortcut menu.

Check that out in the Help and you should be set.  To find out what the options are, open a new macro sheet and select the RunCommand Action in the top pane, then explore the options in the bottom pane.  I think it will look like this in a VBA module:
DoCmd.RunCommand acCmdOpenFile
 or acCmdFileOpen
That should open the ACCESS file open dialog for the user.
0
 
BrianWrenCommented:
Say Tomk:  How about proposing your answers as comments, instead of locking the questions will partial answers and guesses?  Tomb, if I were you I would reject Tomk's proposed 'answer,' since it really isn't.

I have had bad luck with the Common Dialog ActiveX object.  It's easy to use, hard to distribute.

API calls ar ethe way to go.  It gives you complete control over all the aspects, and makes you feel like a hero when it works.

The web site dtomyn recommended is outstanding!

Your solution can definitely be found there.
0
 
TomdpAuthor Commented:
Tomk, I don't want to open an access database (as your method suggests), I just want the open dialog box to have a user select a file. My code will open it
0
 
TomdpAuthor Commented:
Totally wild website indeed. Should have kept it for yourself :)
0
 
dtomynCommented:
Tomdp,
Yeah, that site is excellent and will allow you to get a bunch of expert points in this Access topic area if you hang around here long enough (and obviously if you have time).  The problem with keeping it "secret" (I am sure there are a number of experts that use that site as well) is that it is hard to give credit where credit is due on code that you post.  That is, I am always hesitant to post code that I obviously did not create myself, yet not give the credit to the site where I got it from.
0
 
tomk120999Commented:
brianwren, Thanks for the comment, I got another such and appreciate them.  However that wasn't a guess since I've used the technique many times in VBA, In VB the common dialg box control is the one.  Stay on me, I'll develope some manners!

good luck as usual...
0
 
tomk120999Commented:
brianwren, Thanks for the comment, I got another such and appreciate them.  However that wasn't a guess since I've used the technique many times in VBA, In VB the common dialg box control is the one.  Stay on me, I'll develope some manners!

good luck as usual...
0
All Courses

From novice to tech pro — start learning today.