DoCmd.OpenForm Method (Access)
The OpenForm method carries out the OpenForm action in Visual Basic.
Syntax
식 .OpenForm(FormName, View, FilterName, WhereCondition, DataMode, WindowMode, OpenArgs)
식 A variable that represents a DoCmd object.
Parameters
Name |
Required/Optional |
Data Type |
Description |
---|---|---|---|
FormName |
필수 |
Variant |
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, Microsoft Access looks for the form with this name first in the library database, then in the current database. |
View |
선택 |
AcFormView |
A AcFormView constant that specifies the view in which the form will open. The default value is acNormal. |
FilterName |
선택 |
Variant |
A string expression that's the valid name of a query in the current database. |
WhereCondition |
선택 |
Variant |
A string expression that's a valid SQL WHERE clause without the word WHERE. |
DataMode |
선택 |
AcFormOpenDataMode |
A 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. |
WindowMode |
선택 |
AcWindowMode |
A AcWindowMode constant that specifies the window mode in which the form opens. The default value is acWindowNormal. |
OpenArgs |
선택 |
Variant |
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 the OpenArgs argument, and then use the FindRecord method to move the focus to the record for the client with the specified name. |
Remarks
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 Where Condition action argument in the Macro window, whose maximum length is 256 characters).
Example
The following 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'"
The following example opens the frmMainEmployees form in Form view and displays only records that apply to the department chosen the cboDept combo box. The displayed records can be edited, and new records can be added.
Sample code provided by: Bill Jelen, MrExcel.com | About the Contributors
Private Sub cmdFilter_Click()
DoCmd.OpenForm "frmMainEmployees", , , "DepartmentID=" & cboDept.Value
End Sub
The following example shows how to use the WhereCondition argument of the OpenForm method to filter the records displayed on a form as it is opened.
Sample code provided by: The Microsoft Access 2010 Programmer’s Reference | About the Contributors
Private Sub cmdShowOrders_Click()
If Not Me.NewRecord Then
DoCmd.OpenForm "frmOrder", _
WhereCondition:="CustomerID=" & Me.txtCustomerID
End If
End Sub
About the Contributors
Holy Macro! Books에서는 Microsoft Office 사용자를 위한 재미있는 서적을 다수 출판하고 있습니다. 전체 카탈로그는 MrExcel.com(영문일 수 있음)에서 확인할 수 있습니다.
Wrox Press(영문일 수 있음)는 프로그래머가 프로그래머를 위해 집필한 서적을 전문으로 출판하는 업체로, 이러한 서적에서는 실제 프로그래밍 관련 문제에 대한 신뢰할 수 있는 해결 방법을 제공합니다.