DoCmd.OpenForm (Access)
The OpenForm method carries out the OpenForm action in Visual Basic.
You can use the OpenForm method to open a form in Form view, form Design view, Print Preview, or Datasheet view. You can select data entry and window modes for the form and restrict the records that the form displays. The maximum length of the WhereCondition argument is 32,768 characters (unlike the WhereCondition action argument in the Macro window, whose maximum length is 256 characters).
OpenForm (FormName, View, FilterName, WhereCondition, DataMode, WindowMode, OpenArgs)
DoCmd.OpenForm "Employees", , ,"LastName = 'King'"
Arguments
The following argument is required
FormName (String) - A string expression that's the valid name of a form in the current database. If you execute Visual Basic code containing the OpenForm method in a library database, Access looks for the form with this name first in the library database, and then in the current database.
Optional arguments
The following arguments are optional
View (AcFormView) - An AcFormView constant that specifies the view in which the form will open. The default value is acNormal.
Possible values are
acDesign | The form opens in Design view. |
acFormDS | The form opens in Datasheet view. |
acFormPivotChart | The form opens in PivotChart view. |
acFormPivotTable | The form opens in PivotTable view. |
acLayout | The form opens in Layout view. |
acNormal | The form opens in Form view. |
acPreview | The form opens in Print Preview. |
FilterName (String) - A string expression that's the valid name of a query in the current database.
WhereCondition (String) - A string expression that's a valid SQL WHERE clause without the word WHERE.
DataMode (AcFormOpenDataMode) - An AcFormOpenDataMode constant that specifies the data entry mode for the form. This applies only to forms opened in Form view or Datasheet view. The default value is acFormPropertySettings.
Possible values are
acFormAdd | The user can add new records but can't edit existing records. |
acFormEdit | The user can edit existing records and add new records. |
acFormPropertySettings | The user can only change the form's properties. |
acFormReadOnly | The user can only view records. |
WindowMode (AcWindowMode) - An AcWindowMode constant that specifies the window mode in which the form opens. The default value is acWindowNormal.
Possible values are
acDialog | The form or report's Modal and PopUp properties are set to Yes. |
acHidden | The form or report is hidden. |
acIcon | The form or report opens minimized in the Windows taskbar. |
acWindowNormal | The form or report opens in the mode set by its properties. |
OpenArgs (String) - 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 that 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 the OpenArgs argument, and then use the FindRecord method to move the focus to the record for the client with the specified name.