ACC97: Visual Basic Example for CommonDialog Control Won't WorkLast reviewed: August 29, 1997Article ID: Q166291 |
The information in this article applies to:
SYMPTOMSAdvanced: Requires expert coding, interoperability, and multiuser skills. The example provided in the "CommonDialog control" Help topic does not work in Microsoft Access 97. Microsoft Visual Basic version 4.0 and later has the capability of creating an array of controls. This capability does not exist in Visual Basic for Applications; therefore, some Visual Basic examples that use control arrays cannot be fully implemented in Microsoft Access 97. This article discusses the Visual Basic example for the CommonDialog control, which uses a control array in the Form_Paint procedure. This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to the "Building Applications with Microsoft Access 97" manual.
RESOLUTIONIf you want to implement the Visual Basic example for the CommonDialog control, you must exclude or replace the Form_Paint procedure used in the example, and modify the Command1_Click procedure.
Excluding the Form_Paint ProcedureIf you decide to exclude the Form_Paint procedure, you can create the form controls used in the example manually in Design view of your form:
Form: Form1 ----------------- Option Group: Name: Frame0 Option Button: Name: Option1 OptionValue: 1 Option Button: Name: Option2 OptionValue: 2 Option Button: Name: Option3 OptionValue: 3 Option Button: Name: Option4 OptionValue: 4 Option Button: Name: Option5 OptionValue: 5 Option Button: Name: Option6 OptionValue: 6 Command Button: Name: Command1 OnClick: [Event Procedure] Common Dialog Control: Name: CommonDialog1 Replacing the Form_Paint ProcedureYou can replace the Private Sub Form_Paint procedure with a standard procedure (a procedure in a module outside the form) that will programmatically create the form and the option button controls for you. The following code is an example of how to do this. NOTE: This code is not considered an efficient solution if you are only creating a few forms. The following code becomes more useful if you need many forms. For example, the Microsoft Access Form Wizard uses similar code.
Modifying the Command1_Click ProcedureWhether you create the form and its controls manually or in code, you must also modify the Command1_Click procedure in the example so it does not reference the control array. Note that the only difference in the following code from that in the Help example is that references to the Option1 control array are replaced with the value of the option group, and the name of the Help file is changed to a Microsoft Access Help file, Acmain80.hlp. Type the following procedure in the class module of your form:
Private Sub Command1_Click() If Frame0.Value = 1 Then ' If Open option button selected, CommonDialog1.ShowOpen ' display Open common dialog box. ElseIf Frame0.Value = 2 Then ' Or, CommonDialog1.ShowSave ' display Save common dialog box. ElseIf Frame0.Value = 3 Then ' Or, CommonDialog1.ShowColor ' display Color common dialog box. ElseIf Frame0.Value = 4 Then ' Or, CommonDialog1.Flags = cdlCFBoth ' Flags property must be set to ' cdlCFBoth, cdlCFPrinterFonts, ' or cdlCFScreenFonts before using ' ShowFont method. CommonDialog1.ShowFont ' Display Font common dialog box. ElseIf Frame0.Value = 5 Then ' Or, CommonDialog1.ShowPrinter ' display Printer common dialog box. ElseIf Frame0.Value = 6 Then ' Or, CommonDialog1.HelpFile = "ACMAIN80.HLP" CommonDialog1.HelpCommand = cdlHelpContents CommonDialog1.ShowHelp ' Display Visual Basic Help contents topic. End If End Sub MORE INFORMATIONMost of the Visual Basic Help files in Microsoft Access 97 come from the Microsoft Visual Basic product. When you view the "CommonDialog control" Help topic, you can click the Example jump at the top of the page to view the code example. The first procedure in the example is called:
Private Sub Form_Paint ()A closer look at this procedure indicates that it will create an array of controls when a form is first opened. In other words, it will programmatically create option buttons on the form when it opens. This is indicated by the following code:
For i = 1 To 5 Load Option1(i) ' Add five option buttons to array. Option1(i).Top = Option1(i - 1).Top + 350 Option1(i).Visible = True Next iIf you use this example in Microsoft Visual Basic version 4.0 or later, you will find that the code works flawlessly. However, Visual Basic for Applications, the programming language that is included with Microsoft Access 97, is a subset of Microsoft Visual Basic. Visual Basic for Applications does not have the full functionality found in Microsoft Visual Basic. The ability to create control arrays is one of the features excluded from Visual Basic for Applications; therefore, so you cannot use the example for the CommonDialog control, as written, in a Microsoft Access 97 database.
REFERENCESFor more information about ActiveX components, search the Help Index for "ActiveX controls."
|
Additional query words: common dialog
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |