The author of that FAQ copied the code from some book, but he apparently uses Access 2000 or later, and he omitted a piece you need for Access 97.
CommonDialogConstants is a standard (not class) module you should create. Into it, copy the declarations between the Public Enum and End Enum statements, but insert "Const" in front of each line. For example, the first line you enter into CommonDialogConstants should be:
Code:
Const cdlOFNAllowMultiselect = &H200
You should also include the declaration for cdlCancel in the subsequent Enum definition, commenting the latter out.
What's going on here is that Enum definitions are not supported in Access 97 (VBA5), so you have to substitute Const declarations. But Public Const declarations aren't allowed inside a class module, so you have to create a standard module for them. (Actually, you could just put them into any existing standard module, and it would work the same, but using a separate module will make it easier to copy the code to the next database you want to use it in.)
You said:
What am I doing in this line of code?
Dim cmdlgOpenFile As New clsCommonDialog
Class module clsCommonDialog contains the code that displays the Open or Save dialog. It could have been written as a set of ordinary procedures in a standard module, but putting it in a class module makes it easier to "plug into" an application without having to worry about duplicate names. Because it's a class module, you have to create an object of that class in order to call its procedures (which, for a class, are called properties and methods), and in order to create an object you need an object variable to hold a reference to it; otherwise, it would just disappear right after you created it. The cmdlgOpenFile variable is that object variable.
Normally, you create an object and assign it to an object variable like this:
Code:
Set variable = New Object
This declaration includes the New keyword, however. When you do that, VBA automatically executes a statement like the above the first time the variable is used in a statement. That saves you from having to do it yourself, although there's a tiny penalty in execution speed because VBA has to test whether the object has been created
every time you use the variable.
Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein