Microsoft KB Archive/210595

= ACC2000: How to Use the CreateControl and CreateReportControl Functions =

Article ID: 210595

Article Last Modified on 7/16/2004

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q210595



Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).



SUMMARY
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) 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 Control Source 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: Set MyControl = CreateControl(MyForm.Name, 109) With MyControl .Width = 1500 .Height = 200 .Top = 440 .Left = 200 End With In addition to the form name and the code for the type of control, you can also specify the form or report section in which you want Microsoft Access to place the control.

