Article ID: 166291
Article Last Modified on 1/19/2007
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
Sub CreateControls()
Dim frm As Form
Dim ctlOptGrp As Control, ctlOptBtn As Control, ctlLabel As Control
Dim intLeft As Integer, intTop As Integer, intWidth As Integer
Dim intHeight As Integer
Dim i As Integer
'''''''''''''''''''
'Create a new form.
'''''''''''''''''''
Set frm = CreateForm
''''''''''''''''''''''''''''''''''''''''''
'Set coordinates for Option Group control.
''''''''''''''''''''''''''''''''''''''''''
intLeft = 1440 * 1.75
intTop = 1440 * 0.25
intWidth = 1440 * 1.5
intHeight = 1440 * 1
''''''''''''''''''''''''''''''''''''''''''''''
'Create an Option Group in the Detail section.
''''''''''''''''''''''''''''''''''''''''''''''
Set ctlOptGrp = CreateControl(frm.Name, acOptionGroup, acDetail, _
"", "", intLeft, intTop, intWidth, intHeight)
''''''''''''''''''''''''''''''''''''''''''''''''''
'Initialize coordinates for Option Button controls.
''''''''''''''''''''''''''''''''''''''''''''''''''
intLeft = 1440 * 2
intTop = 1440 * 0.5
''''''''''''''''''''''''''''''''''''''''''''
'Create Option Buttons for the Option Group.
''''''''''''''''''''''''''''''''''''''''''''
For i = 1 To 6
Set ctlOptBtn = CreateControl(frm.Name, acOptionButton, _
acDetail, ctlOptGrp.Name, "", intLeft, intTop)
ctlOptBtn.OptionValue = i
intTop = intTop + (1440 * 0.25)
Next i
''''''''''''''''''''''''''''''''''''''''''''''''
'Initialize coordinates for Option Button labels.
''''''''''''''''''''''''''''''''''''''''''''''''
intLeft = 1440 * 2.25
intTop = 1440 * 0.455
''''''''''''''''''''''''''''''''''''''''''''''''''
'Create Option Button Labels for the Option Group.
''''''''''''''''''''''''''''''''''''''''''''''''''
Set ctlLabel = CreateControl(frm.Name, acLabel, acDetail, _
"Option1", "Open", intLeft, intTop)
intTop = intTop + (1440 * 0.25)
Set ctlLabel = CreateControl(frm.Name, acLabel, acDetail, _
"Option2", "Save", intLeft, intTop)
intTop = intTop + (1440 * 0.25)
Set ctlLabel = CreateControl(frm.Name, acLabel, acDetail, _
"Option3", "Color", intLeft, intTop)
intTop = intTop + (1440 * 0.25)
Set ctlLabel = CreateControl(frm.Name, acLabel, acDetail, _
"Option4", "Font", intLeft, intTop)
intTop = intTop + (1440 * 0.25)
Set ctlLabel = CreateControl(frm.Name, acLabel, acDetail, _
"Option5", "Printer", intLeft, intTop)
intTop = intTop + (1440 * 0.25)
Set ctlLabel = CreateControl(frm.Name, acLabel, acDetail, _
"Option6", "Help", intLeft, intTop)
''''''''''''''''''
'Restore the form.
''''''''''''''''''
DoCmd.Restore
End Sub
CreateControls
Command Button:
Name: Command1
OnClick: [Event Procedure]
Common Dialog Control:
Name: CommonDialog1
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
Private Sub Form_Paint ()
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 i
If 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.
Additional query words: common dialog
Keywords: kbprogramming KB166291