ACC: CreateControl() and CreateReportControl() Functions (93095)
The information in this article applies to:
- Microsoft Access 1.0
- Microsoft Access 1.1
- Microsoft Access 2.0
- Microsoft Access for Windows 95 7.0
- Microsoft Access 97
- Microsoft Visual Basic for Applications 1.0
This article was previously published under Q93095 SUMMARY
Advanced: Requires expert coding, interoperability, and multiuser skills.
This article discusses the Microsoft Access functions CreateControl() and
CreateReportControl(). If you want to write your own form wizards or
report wizards, you can use these functions to create controls on a form
or report that is open in Design view.
MORE INFORMATION
The CreateControl() and CreateReportControl() functions require two
arguments: the name of the form or report as a string value, and a numeric
code that represents the control type.
Both CreateControl() and CreateReportControl() return a control object
value. Therefore, you define a control variable first, and then you set
the control variable equal to the function name.
For example, the following procedure creates a form, and then adds a
command button to the form:
Dim MyForm As Form, MyControl As Control
Set MyForm = CreateForm()
Set MyControl = CreateControl(MyForm.Name, 104)
NOTE: In Microsoft Access 1.x, use MyForm.FormName instead of MyForm.Name).
When the procedure is finished, you can modify the properties of the new
control by using the control variable that you defined. For example, you
can change the control's Width and Caption properties with these
statements:
MyControl.Width = 2000
MyControl.Caption = "&Sum All Records"
For controls that are frequently associated with a field in a table or
query, you can modify the ControlSource property to bind the control to
the field.
By default, some controls are created with their Height and Width
properties set to zero to make them invisible. Also by default, controls
appear in the upper-left corner of the form. You can adjust the size and
position of a control immediately after you create it by changing the
control's properties. For example, the following code creates, sizes, and
moves a text box by changing the properties:
In Microsoft Access 7.0 and 97:
Set MyControl = CreateControl(MyForm.FormName, 109)
With MyControl
.Width = 1500
.Height = 200
.Top = 440
.Left = 200
End With
In Microsoft Access 1.x and 2.0:
Set MyControl = CreateControl(MyForm.FormName, 109)
MyControl.Width = 1500
MyControl.Height = 200
MyControl.Top = 440
MyControl.Left = 200
In addition to the form name and the code for the type of control, you can
also specify the form or report section where you want Microsoft Access to
place the control.
REFERENCES
For more information about creating a control in code, search the Help
Index for CreateControl or CreateReportControl or ask the Microsoft
Access 97 Office Assistant.
Modification Type: | Minor | Last Reviewed: | 8/15/2005 |
---|
Keywords: | kbinfo kbProgramming KB93095 |
---|
|