CreateForm, CreateReport Functions

Description

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 have 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. If you specify a database other than the current database, that database must be open as a library database.

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. 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   You can 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. Note that if the database specified by the database argument is not the current database, that database must be open as a library database. For more information on library databases, see Chapter 12, "Using Library Databases and Dynamic-Link Libraries," in Building Applications with Microsoft Access 97.

Note If you have created a form or report template in another database that you would like to use as a template, you can simply import it into the current database, rather than loading a library database. Then check to make sure that the proper form or report name is listed in the Form Template or Report Template box on the Forms/Reports tab of the Options dialog box. Forms and reports subsequently created with the CreateForm or CreateReport function will be based on this template.

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 on the Forms/Reports tab of the Options dialog box.

When you create a form or report with the CreateForm or CreateReport function, the form's or report's HasModule property is set to False (0). You can set this property to True (–1) if you want the new form or report to have a class module.

The CreateForm and CreateReport functions create minimized forms and reports.

See Also   CreateControl, CreateReportControl functions.

Example

The following example creates a report in the current database by using the template specified by the Report Template setting on 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 new form in the Northwind sample database based on the Customers form, and sets its RecordSource property to the Customers table. Run this code from the Northwind sample database.

Sub NewForm()
    Dim frm As Form

    ' Create form based on Customers form.
    Set frm = CreateForm( , "Customers")
    DoCmd.Restore
    ' Set RecordSource property to Customers table.
    frm.RecordSource = "Customers"
End Sub