Howto: Open a file dialog box OR what happened to the FileDialog variable type?

K

Ken Eisman

Using Access 2003.

I need to open a file dialog box to get the path to a picture.

I cut and pasted the example from the online help:

*****************************************
Dim dlgOpen As FileDialog

Set dlgOpen = Application.FileDialog( _
FileDialogType:=msoFileDialogOpen)

With dlgOpen
.AllowMultiSelect = True
.Show
End With
****************************************

Changed msoFileDialogOpen to msoFileDialogFilePicker.

But VBA yells at me that FileDialog in not a good variable type.

Does anyone know what I'm doing wrong?

TIA

Ken
 
D

Dirk Goldgar

Douglas J. Steele said:
Don't bother using the FileDialog object: call the API instead. It's
more reliable.

There's complete code available at
http://www.mvps.org/access/api/api0001.htm at "The Access Web".

However, in response to your question, the FileDialog object is

.... defined in the Microsoft Office 11.00 Object Library, so you have to
set a reference (Tools -> References...) to that library before you can
declare a variable of that type.

(Something seems to have happened to Doug! Call Scotland Yard!)
 
J

Jeff Conrad

Dirk Goldgar said:
(Something seems to have happened to Doug! Call Scotland Yard!)

I was wondering about that all afternoon too!
I thought he just took a snooze right on the keyboard in mid-thought.
 
K

Ken Eisman

That did it Doug! Thanks grunches! I really appreciate your help.

At present, that API call looked a bit too complicated for me so I'm using
the FileDialog object. But I plan on playing with the API in the future to
see if I can get it to work for me.

Is there a way that I should have known that I needed to load that library
for that object? If that information is available somewhere, it would help
me to keep from asking you all these qeustions.

Thanks again
Ken
 
D

Dirk Goldgar

Ken Eisman said:
Is there a way that I should have known that I needed to load that
library for that object? If that information is available somewhere,
it would help me to keep from asking you all these qeustions.

I don't think you missed anything obvious. If you were coding, and
typed "FileDialog" and pressed F1, you'd get the help topic for the
Application.FileDialog property. The example given in that help topic
doesn't tell you that, although you can get at the FileDialog object by
way of that property without ever setting a reference to the Office
Object Library, you can't declare an object of that type or use the
associated "msoFileDialog..." constants without setting that reference.

If, while viewing that topic, you click on the link to the FileDialog
object itself, you *might* notice that the topic that comes up is part
of the "Microsoft *Office* Visual Basic Reference" (emphasis mine), not
the "Microsoft Access Visual Basic Reference". So if you were really,
really sharp -- and experienced -- that would tip you off.

If you search the Microsoft KnowledgeBase, at

http://support.microsoft.com/default.aspx?scid=fh;EN-US;KBHOWTO

for "FileDialog" under the product "Access 2002", search type "Full
Text", you'll find this article, among others:

http://support.microsoft.com/default.aspx?scid=kb;EN-US;279508
How to display and use the file dialog box in Access 2002

which does explain about the required reference and how to set it. The
KnowledgeBase is a good resource, though searching it does not always
return hits that it should, for some reason. You can also use Google to
search site:microsoft.com, and often find hits *in the KnowledgeBase*
that the built-in KB search doesn't find.

Another very good resource is The Access Web:

http://www.mvps.org/access
 
S

Sam Hobbs

I am a beginner to Access also and the documentation sure can be
frustrating. I tried your sample code, which I see is copied from the
documentation. I got the same error. So I tried to find the answer in the
manner I usually would. I searched all of the (VB for Access) documentation
for "FileDialog" and found nothing about the need for the reference. I do
know from experience that if VB can't find something that it is supposed to
be able to find, then there is probably a reference missing. But even if I
assume that is the solution, the documentation does not specify what the
reference is that is needed.

Usually, when I can't find something in the Office documentation, I search
the MSDN next. If I can't find something there, then I search the internet.
Then if I can't find something I ask in a group or forum such as this.
However there are some things for which I can't think of a relevant
combination of keywords to search for, and then I ask in a group or forum
and hope that people understand I have searched as well as I knew how to.

The documentation of the Windows SDK API is a good example of the right way
to do things, to the extent that the documentation of every function
identifies the header file, library and such that is needed for it. It would
help if a similar methodology were used for Office objects.
 
B

bobby.j.cross

I have the reference included and check marked, but I still get an error on
type. Any other help? MSN was not helpful at all.
 
D

Dirk Goldgar

"bobby.j.cross<junkthis>@lmco.<junk>com @lmco.
I have the reference included and check marked, but I still get an
error on type. Any other help? MSN was not helpful at all.

It's not a good idea to post a new question into a thread that is a
month old. People may very well not see it.

As the question itself, please post the code you are using, and the
exact error message you are getting, and indicate exactly which line is
raising the error.
 
D

Dan Kean

Hi all,

I've been having the same trouble (been ages ince i messed weith vb)

code:
Dim dlgOpen As FileDialog

Set dlgOpen = Application.FileDialog( _
FileDialogType:=msoFileDialogOpen)

With dlgOpen
.AllowMultiSelect = True
.Show
End With

the error I'm getting is: named argumen not found on line 3

any idea what Im doing wrong?

Thanx in advance
Dan
 

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