ACC: Using CreateForm() and CreateReport() Functions

ID: Q93096

The information in this article applies to:

SUMMARY

Moderate: Requires basic macro, coding, and interoperability skills.

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.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access versions 1.x and 2.0. For more information about Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x or the "Building Applications" manual in Microsoft Access version 2.0.

MORE INFORMATION

The CreateForm() and CreateReport() functions are 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 an iconized state.

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

The examples in the paragraphs that follow refer to creating a new form 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. An example of how to do this is:

   Dim MyForm As Form
   Set MyForm = CreateForm()

After the form is created, it is open in Design view and you can set or change its properties, such as the RecordSource property:

   MyForm.RecordSource = "Categories"

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 example creates a new form and sets the Height and KeepTogether properties of the detail section:

   Dim MyForm As Form
   Set MyForm = CreateForm()
   MyForm.Section(0).Height = 1760
   MyForm.Section(0).KeepTogether = True

REFERENCES

For more information about the CreateForm() and CreateReport() functions, search the Help Index for "CreateForm function" or "CreateReport function."

For information about using the CreateControl() and CreateReportControl() functions, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q93095
   TITLE     : ACC: CreateControl() and CreateReportControl() Functions

Additional query words: wizards
Keywords          : kbprg MdlLib 
Version           : 1.0 1.1 2.0 7.0 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbinfo

Last Reviewed: November 21, 1998