OpenArgs Property

Applies to

Form Object

Report Object

Determines the string expression specified by the OpenArgs argument of the OpenForm method that opened a form. Read/write Variant.

expression.OpenArgs

expression Required. An expression that returns one of the objects in the Applies To list.

Remarks

This property is available only by using a macro or by using Visual Basic for Applications (VBA) code with the OpenForm method of the DoCmd object. This property setting is read-only in all views.

To use the OpenArgs property, open a form by using the OpenForm method of the DoCmd object 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 in 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's 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.

Example

The following example uses the OpenArgs property to open the Employees form to a specific employee record and demonstrates how the OpenForm method sets the OpenArgs property. You can run this procedure as appropriate — for example, when the AfterUpdate event occurs for a custom dialog box used to enter new information about an employee.

Sub OpenToCallahan()
DoCmd.OpenForm "Employees", acNormal, , , _
acReadOnly, , "Callahan"
End Sub
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 If
End Sub

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 DAO.Recordset
Set RS = Me.RecordsetClone
RS.FindFirst "LastName = '" & _
strEmployeeName & "'"
If Not RS.NoMatch Then
Me.Bookmark = RS.Bookmark
End If
End If
End Sub
Share Facebook Facebook Twitter Twitter Email Email

Was this information helpful?

Great! Any other feedback?

How can we improve it?

Thank you for your feedback!

×