One of the ActiveX controls included in the MOD is the Common Dialog control. With this control, you can create the standard dialogs used for various Windows system tasks, including the following:
Opening a file
Saving a file under a new name
Choosing a color
Choosing a font
Printing a file
Running Winhelp.exe
Before Access 95, to access the Common Dialog you had to use Windows API calls. Not anymore. ActiveX controls allow you to access the same functionality without the hassle of setting up for the API call.
Note
To use the Common Dialog control, you must have the Microsoft Office Developer Edition, Visual Basic 5 or 6, or Visual InterDev, Enterprise Edition. This control isn't available in the standard Microsoft Access. When you install the MOD, this control and others are registered automatically.
Let's take an overview of how to use the Common Dialog control, and then examine the following examples:
Using the ActiveX control to locate the back end to the World Wide Video Application (Open File dialog)
Setting a new default printer for the World Wide Video Application (Printer dialog)
After it's placed on a form, the Common Dialog control isn't very impressive visually. The Calendar control, on the other hand, looks great because you can actually see a calendar in Design mode. You can see in Figure B.9 the Common Dialog control in the upper-right corner of the frmWindowsCommonControlsRichTextbox form in the Chap14.mdb database, located in the ExamplesChap14 folder on the CD-ROM.
Even worse, at runtime you can't even see the control until it's activated with one of the Show methods (discussed shortly).
You can also see from Figure B.9 that quite a few properties are specific to the Common Dialog control. Before you panic, keep in mind that different dialogs use the various properties. A better way to look at the properties is through the specific Common Dialog Properties sheet.
To access the property sheet for the Common Dialog control, double-click the control itself. Figure B.10 shows a view of the tabs on the Common Dialog control-specific property sheet.
You can even see the different tabs that represent the types of dialogs available. Because so many properties are available to use, specific properties are covered for two examples later in this chapter.
You can't activate the control except when using the Show methods, including ShowOpen, ShowSave, ShowColor, ShowFont, ShowPrint, and ShowHelp. In generic terms, the following steps set up a Common Dialog ActiveX control:
1. |
Place a Common Dialog control on the form by using the method described earlier in the section “Placing an ActiveX Control on a Form.” |
2. |
By using either the Access property sheet or the ActiveX Control property sheet, set the necessary properties for the dialog type you want to use. You can also set the properties by using code so that a control can be used for more than one purpose (discussed in the next section). |
3. |
In an event procedure, call the Show method of your choice. |
An example of these steps, with specifics, is given in the following section.
Using the common dialog control to locate a file is very straightforward. You can see this by the code listed here for the click event of the command button with the label “Load File” (cmdLoad), on the frmWindowsCommonControlsRichText form.
Private Sub cmdLoad_Click() Me!ocxCommon.Filter = "Rich Text Format files|*.rtf" Me!ocxCommon.ShowOpen Me!ocxRichText.LoadFile Me!ocxCommon.Filename, 0 End Sub
The filter property is the only property being set. You can add more filters just by adding the pipe “|” symbol to the end of the current filter string, followed by the additional description and skeleton. The following is a list of some of the other properties that can be used with the ShowOpen method of the common dialog.
You can see the dialog in action here in Figure B.11.
This process is just one of many of an unending number of ways to use the Common Dialog ActiveX control, even with just the ShowOpen method. Another useful method is the ShowPrinter method, for manipulating the Windows default system printer.
Usually when you create reports, you want the report to use the default printer that's set for Windows. You can switch default printers in a number of ways. Some applications, such as Microsoft Word, allow you to change the default printer when you choose the Print command. Another way to change the default printer is by going to the Windows 95 desktop and choosing a new default printer from the list of printers in the My Computer's Printers window.
When dealing with users, you don't want to make them perform these other steps. The ideal way to deal with setting the printer is to have users either set a new default printer at report time or just go to a system utilities form once to handle it. The latter choice, discussed here, is shown in Design mode in Figure B.12. This particular utility form, ap_SystemUtilities, is found in VidApp.mdb. (A system utility form is one that contains various utilities used for the system or the current application.)
Note
This example requires no setting of properties and has only one method call—ShowPrinter.
By looking at the event procedure behind the cmdChangePrinter OnClick event, you see the following code:
Private Sub cmdChangePrinter_Click() Me!ocxChangePrinter.ShowPrinter End Sub
That's all there is. You place the control on the form, create an event procedure on the OnClick event on the command button, and place the preceding code lines. Figure B.13 shows the Print dialog that appears when you click the command button.
Although properties aren't needed for this example, Figure B.14 shows the Common Dialog control property sheet's Print page.
Now that you've seen two ways of using the Common Dialog ActiveX control, try the other Show methods mentioned, including ShowSave, ShowColor, and ShowFont.
13.59.177.14