CreateForm, CreateReport Functions

Description

The CreateForm function creates a form and returns a Form object. The CreateReport function creates a report and returns a Report object.

For example, suppose you are building a custom wizard to create a sales report. You can use the CreateReport function in your wizard to create a new report based on a specified report template.

Syntax

CreateForm([database[, formtemplate]])CreateReport([database[, reporttemplate]])

The CreateForm and CreateReport functions take the following arguments.

Argument Description
database A string expression identifying the name of the database that contains the form or report template you want to use to create a form or report. If you omit this argument, the current database (the value returned by the CurrentDb function) is used.
formtemplate, reporttemplate A string expression identifying the name of the form or report you want to use as a template to create a new form or report. To create a form or report based on the default template, set this argument to Normal. If you omit this argument, Microsoft Access bases the new form or report on the template specified by the Forms/Reports tab of the Options dialog box, available by clicking Options on the Tools menu.


Remarks

Use the CreateForm and CreateReport functions when designing a wizard that creates a new form or report.

The CreateForm and CreateReport functions open a new, minimized form or report in form Design view or report Design view, respectively.

The form or report you specify for formtemplate or reporttemplate can be a form or report that you have created specifically to be used as a template, or any other form or report in the database identified by the database argument.

If the name you use for the formtemplate or reporttemplate argument isn’t valid, Visual Basic uses the form or report template specified by the Form Template or Report Template setting in the Forms/Reports tab of the Options dialog box, available by clicking Options on the Tools menu.

CreateForm and CreateReport create minimized forms and reports.

Note If you have created a form or report template in another database, the name of that template will be displayed in the Form Template or Report Template options in the Forms/Reports tab of the Options dialog box for every database created in Microsoft Access. In order to create a form or report based on a template that is not in your current database, however, you must either specify the other database in the database argument, or specifically import the template into the current database.

See Also

CreateControl, CreateReportControl Functions.

Example

The following example creates a report in the current database using the template specified by the Report Template setting in the Forms/Reports tab of the Options dialog box.


Sub NormalReport()
    Dim rpt As Report



    Set rpt = CreateReport    ' Create minimized report.
    DoCmd.Restore    ' Restore report.


End Sub

The next example creates a form in the current database that is based on the Customers form in the Northwind sample database, and sets its RecordSource property to the Customers table in the current database. If the currently open database is the Northwind sample database, then you could set the first argument to a zero-length string.


Sub NewForm()


    Dim frm As Form


    ' Create form based on Customers form in Northwind sample database.


    Set frm = CreateForm("Northwind.mdb", "Customers")


    DoCmd.Restore
    ' Set RecordSource to Customers table.
    frm.RecordSource = "Customers"Sub