This tutorial explains how to use Access DoCmd.OpenForm Method to open Access Form in Access VBA
Access DoCmd.OpenForm Method – open Access Form
DoCmd.OpenForm Method is used to open Access Form.
Syntax of Access DoCmd.OpenForm Method- open Access Form
DoCmd.OpenForm(FormName, View, FilterName, WhereCondition, DataMode, WindowMode, OpenArgs)
FormName | Name of Form (in String) | ||||||||||||||||||||||||
View | Optional. How you want to view the Form
|
||||||||||||||||||||||||
FilterName | Input SQL String or existing Query name to use its Where Clause (but not Record Source) | ||||||||||||||||||||||||
WhereCondition | Input Where Clause in String (without Where keyword) | ||||||||||||||||||||||||
DataMode | Optional. How you want the input mode to be in Form view or Datasheet view
|
||||||||||||||||||||||||
WindowMode | Optional. Set the display Windows mode
|
||||||||||||||||||||||||
OpenArgs | Optional. 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. |
Example of using SQL String in FilterName argument
FilterName argument extracts the criteria in SQL / Query to use in Form Filter. If you only want to write the criteria to use it in Form, use WhereCondition argument (see below).
The following code defines a SQL string and use its criteria (not Record Source) in Result_Form when Result_Form is opened.
emplID_global = EmplID_tb
bookingDate_global = DateSerial(Year(bookingDate_tb), Day(bookingDate_tb), Month(bookingDate_tb))
searchCriteria = "[Empl ID] =" & "'" & emplID_global & "'" & " AND [Booking Date]=#" & bookingDate_global & "#"
searchSQL_global = "Select * From [Schedule_Table] WHERE " & searchCriteria
DoCmd.OpenForm "Result_Form", , searchSQL_global
Example of using Query in FilterName argument
The following code uses criteria in Query (tempQry) in Result_Form when Result_Form is opened.
DoCmd.OpenForm "Result_Form", , "tempQry"
Example of using String in WhereCondition argument
The following code uses searchCriteria as criteria (statement after WHERE Clause) in Result_Form when Result_Form is opened.
emplID_global = EmplID_tb
bookingDate_global = DateSerial(Year(bookingDate_tb), Day(bookingDate_tb), Month(bookingDate_tb))
searchCriteria = "[Empl ID] =" & "'" & emplID_global & "'" & " AND [Booking Date]=#" & bookingDate_global & "#"
DoCmd.OpenForm "Result_Form", , ,searchCriteria
Outbound References
https://msdn.microsoft.com/en-us/library/office/ff820845.aspx?f=255&MSPPError=-2147217396