Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: Using CreateForm() and CreateReport() Functions


View products that this article applies to.

This article was previously published under Q210594
Advanced: Requires expert coding, interoperability, and multiuser skills.

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

↑ Back to the top


Summary

This article discusses the Microsoft Access functions CreateForm() and CreateReport(). If you intend to write your own form wizard or report wizard, you can use these functions to create and customize a blank form or report to which you can add controls.

↑ Back to the top


More information

The CreateForm() and CreateReport() functions are the Visual Basic code equivalents of creating a new form or report in Design view. When you run these functions, they create a new blank form or report in a minimized state.

Both functions return an object value that you can use for further manipulation, and neither function requires parameters.

The sample code in the paragraphs that follow applies to creating new forms using the CreateForm() function; however, the same information also applies to creating reports with the CreateReport() function.

To use the CreateForm() function, first define a form object variable, and then assign the variable to the function name, as in the following sample code:
Public Function MakeNewForm()
    Dim MyForm As Form
    Set MyForm = CreateForm()
End Function
				
After the form is created, it is open in Design view. You can set or change its properties, such as the RecordSource property, at the same time as you create the form by adding a line to the function:
Public Function MakeNewForm()
    Dim MyForm As Form
    Set MyForm = CreateForm()
    MyForm.RecordSource = "Categories"
End Function
				
You can also access and change the properties of each of the form's sections using the Section property. The Section property is actually an array, with each array value referencing a section on the form. Form sections are stored in the Section property array as follows:
Section(0) - Detail Section
Section(1) - Form Header
Section(2) - Form Footer
Section(3) - Page Header
Section(4) - Page Footer
Report sections are stored in the Section property array as follows
Section(0) - Detail Section
Section(1) - Report Header
Section(2) - Report Footer
Section(3) - Page Header
Section(4) - Page Footer
Section(5) - Group Level 1 Header
Section(6) - Group Level 1 Footer
Section(7) - Group Level 2 Header
and so on.

With this information, you can customize the design of a form section programmatically. The following sample code creates a new form and sets the Height and KeepTogether properties of the Detail section:
Public Function MakeNewForm()
   Dim MyForm As Form
   Set MyForm = CreateForm()
   MyForm.Section(0).Height = 1760
   MyForm.Section(0).KeepTogether = True
End Function
				

↑ Back to the top


References

For more information about the CreateForm() and CreateReport() functions, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type createform, create report methods in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

For additional information about using the CreateControl() and CreateReportControl() functions, click the article number below to view the article in the Microsoft Knowledge Base:
210595� ACC2000: How to Use the CreateControl() and CreateReportControl() Functions

↑ Back to the top


Keywords: KB210594, kbprogramming, kbinfo

↑ Back to the top

Article Info
Article ID : 210594
Revision : 2
Created on : 6/28/2004
Published on : 6/28/2004
Exists online : False
Views : 392