Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

適用對象

Form 物件

Report 物件

決定開啟表單之 OpenForm 方法的 OpenArgs 引數所指定的字串運算式。 讀/寫變數

expression.OpenArgs

運算式 必要。 傳回 [套用至] 清單中其中一個對象的表達式。

備註

只有在使用巨集或使用 Visual Basic for Applications (VBA) 程式碼搭配 DoCmd 物件的 OpenForm 方法時,才可以使用此屬性。 此屬性設定在所有檢視中都是唯讀的。

若要使用 OpenArgs 屬性,請使用 DoCmd 物件的 OpenForm 方法開啟表單,然後將 OpenArgs 引數設定為所需的字串運算式。 OpenArgs 屬性設定之後就可以用於表單的程式碼,例如,用於開啟事件程序時。 您也可以參照巨集 (例如 Open 巨集) 中的屬性設定或運算式 (例如,設定表單上控制項之 ControlSource 屬性的運算式)。

例如,假設您開啟的表單是用戶端的連續表單清單。 如果您希望焦點在表單開啟時移至特定的用戶端記錄,可以將 OpenArgs 屬性設為用戶端的名稱,然後使用 Open 巨集中的 FindRecord 動作,將焦點移至具有指定名稱之用戶端的記錄。

範例

下列範例使用 OpenArgs 屬性,將員工表單開啟到特定的員工記錄,然後示範 OpenForm 方法如何設定 OpenArgs 屬性。 您可以視需要執行此程序,例如,當用於輸入員工新資訊的自訂對話方塊發生 AfterUpdate 事件時。

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

下一個範例使用 FindFirst 方法,找出 OpenArgs 屬性中具名的員工。

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

Need more help?

Want more options?

探索訂閱權益、瀏覽訓練課程、瞭解如何保護您的裝置等等。

社群可協助您詢問並回答問題、提供意見反應,以及聆聽來自具有豐富知識的專家意見。

Was this information helpful?

How satisfied are you with the translation quality?
What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×