ACC: CreateControl() and CreateReportControl() FunctionsLast reviewed: August 29, 1997Article ID: Q93095 |
The information in this article applies to:
SUMMARYAdvanced: Requires expert coding, interoperability, and multiuser skills. This article discusses the Microsoft Access functions CreateControl() and CreateReportControl(). If you intend 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 INFORMATIONYou can use the CreateControl() and CreateReportControl() functions to create new controls on a form or report open in Design view. These functions require two arguments: the name of the form or report as a string value and a numeric code that represents the control type. CreateControl() and CreateReportControl() both 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 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 WithIn Microsoft Access 1.x and 2.0:
Set MyControl = CreateControl(MyForm.FormName, 109) MyControl.Width = 1500 MyControl.Height = 200 MyControl.Top = 440 MyControl.Left = 200In 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.
REFERENCESFor more information about creating a control in code, search the Help Index for "CreateControl" or "CreateReportControl," or ask the Microsoft Access 97 Office Assistant. Keywords : kbprg PgmHowTo SynFnc PgmObj FmrProp Version : 1.0 1.1 2.0 7.0 97 Platform : WINDOWS Hardware : x86 Issue type : kbinfo |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |