Form.
You can use the OpenArgs property to determine the string expression specified by the openargs argument of the OpenForm method that opens a form.
This property is available only in a macro or Visual Basic using the DoCmd.OpenForm method. This property setting is read-only in all views.
To use the OpenArgs property, open a form using the DoCmd.OpenForm method, and set the openargs argument to the desired string expression. The OpenArgs property setting can then be used in code for the form, such as an Open event procedure. You can also refer to the property setting in a macro, such as an Open macro, or an expression, such as an expression that sets the ControlSource property for a control on the form.
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 set the OpenArgs property to the client name, and then use the FindRecord action in an Open macro to move the focus to the record for the client with the specified name.
DoCmd Object; Open, Close Events; OpenForm Action.
The following example uses the OpenArgs property to open an Employees form to a specific employee record and demonstrates how the OpenForm action sets the OpenArgs property. You can run this procedure in an appropriate instance — for example, when the AfterUpdate event occurs for a custom dialog box used to enter new information on an employee. The Open event procedure for the Employees form uses the OpenArgs property to open the form to the specific employee record.
Sub OpenToCallahan() DoCmd.OpenForm "Employees", acNormal, , , acReadOnly, , "Callahan"Sub Form_Open(Cancel As Integer) Dim strEmployeeName As String ' If OpenArgs property contains employee name, ' find corresponding employee record ' and display it on form. For example, if the ' OpenArgs property contains "Callahan", ' move to first "Callahan" record. strEmployeeName = Forms![Employees].OpenArgs If Len(strEmployeeName) > 0 Then DoCmd.GoToControl "LastName" DoCmd.FindRecord strEmployeeName, ,True, , True, , True End IfSub
The next example uses the FindFirst method to locate the employee named in the OpenArgs property.
Private Sub Form_Open(Cancel As Integer) If Not IsNull(Me.OpenArgs) Then Dim strEmployeeName As String strEmployeeName = Me.OpenArgs Dim RS As Recordset Set RS = Me.RecordsetClone RS.FindFirst "[LastName] = '" & strEmployeeName & "'" If Not RS.NoMatch Then Me.Bookmark = RS.Bookmark End If End IfSub