OpenForm Method

Applies To

DoCmd Object.

Description

The OpenForm method carries out the OpenForm action in Visual Basic. For more information on how the action and its arguments work, see the action topic.

Syntax

DoCmd.OpenForm formname [, view] [, filtername] [, wherecondition] [, ådatamode] [, windowmode] [, openargs]

The OpenForm method uses the following arguments.

Argument

Description

formname

A string expression that is the valid name of a form in the current database.

If you execute Visual Basic code containing the OpenForm method in a library database, Microsoft Access looks for the form with this name first in the library database, then in the current database.

view

One of the following intrinsic constants:

acNormal
acDesign
acPreview
acFormDS

acNormal opens the form in Form view.

If you leave this argument blank, the default (acNormal) is assumed.

filtername

A string expression that is the valid name of a query in the current database.

wherecondition

A string expression that is a valid SQL WHERE clause without the word WHERE.

datamode

One of the following intrinsic constants:

acAdd
acEdit
acReadOnly

If you leave this argument blank, the default (acEdit) is assumed.

windowmode

One of the following intrinsic constants:

acNormal

If you leave this argument blank, the default (acNormal) is assumed.


Argument

Description

openargs

A string expression. This expression is used to set the form’s OpenArgs property. This setting can then be used by code in a form module, such as the Open event procedure. The OpenArgs property can also be referred to in macros and expressions.

For example, suppose that the form you open is a continuous-form list of clients. If you want the focus to move to a specific client record when the form opens, you can specify the client name with openargs.

This argument is available only in Visual Basic.


Remarks

The maximum length of the wherecondition argument is 32,768 characters (unlike the Where Condition action argument in the Macro window, whose maximum length is 256 characters).

You can leave an optional argument blank in the middle of the syntax, but you must include the argument’s comma. If you leave a trailing argument blank, don’t use a comma following the last argument you specify.

See Also

Close Method; DoCmd Object; Open, Close Events; OpenArgs Property; OpenForm Action; SelectObject Method.

Example

This example opens the Employees form in Form view and displays only records with King in the LastName field. The displayed records can be edited, and new records can be added.


DoCmd.OpenForm "Employees", , ,"[LastName] = 'King'"