Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Faq 1C also faq705-2484 "How do select a file using the a dialog box. 1

Status
Not open for further replies.

FacilitiesCAD

Technical User
Aug 4, 2003
39
US
faq705-2484

I'm having trouble trying to use this FAQ.

What am I doing in this line of code?

Dim cmdlgOpenFile As New clsCommonDialog

I am using Access97 so I commented out the section talked about here but where is this CommonDialogConstants module stuff he is talking about.


' Values for the Flags property; multiple values can be ORed together.
' In versions of Access prior to Access 2000, comment or delete these
' and use the CommonDialogConstants module (Enum keyword is not
' valid in these versions).

Any help woulb be apreciated.

Tim
 
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
 
Rick,
Thankyou,You have cleared up the contents of the FAQ file. (my network drive is off so I can't test it right now) but your solution does bring me 1 question. Is the difference between a standard module and a class module that a class module is generated at the form level (ie when you build an event to a button on a form) while a standard module is built on the Tab that is labeled module.

Thanks
Tim
 
Rick,
Thanks again, I solved my new question through the help files. I guess I just needed to know that there were two types of modules. (I actually still don't know the difference between the two types of modules but now I know how to generate both types.

Tim
PS I gave you the star
 
To put it as simply as possible, standard modules are like ordinary sequential programming modules, containing constants, variables, and procedures. Class modules are templates for creating objects, as in Object Oriented Programming.

In Access we're familiar with lots of objects, such as Form, Report, and Control objects. These have properties, methods, and (in VBA) events. You have to create an instance of one of these objects before you can use its properties, methods, or events. Every object has an associated class module. Within the class module, any Public variables are simple properties, and Public Sub and Function procedures are methods. (There are also Property procedures that work like properties, for when you need more control than a simple property gives you.)

BTW, the real class module behind forms is called Form, and it's built into Access so you can't see it in the Database Window. The Form class contains all the standard properties and methods of forms. When you create a custom form module, you're actually creating a descendant (child) class of the Form class, which allows you to add additional properties and methods to the form. A similar thing happens with reports. Access is put together this way so that forms and reports are easy to create--you don't have to create and open a recordset, move the data between the record and the form, deal with implementing Undo operations, and lots of other details that go on behind the scenes.

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Thanks again,
My database is up and working know. I've learned alot on customising Access. I may very well make more things in access now than excel.


Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top