访问vba DoCmd.OpenForm“操作被取消”

时间:2012-08-30 19:33:01

标签: forms ms-access parameter-passing access-vba

Private Sub OccurrenceName_AfterUpdate()
If OccurrenceName.Value = "Other" Then
    Dim strTechID As String
    Dim strOccurrenceCt As String
    Dim strOccurrenceDate As String

    strTechID = Me.Parent.tbxTechID.Value
    strOccurrenceCt = Forms![frmEmployeeOccurrenceInput]![tbxOccurrence].Value
    strOccurrenceDate = Me.OccurrenceDate.Value

    Dim strOpenArgs As String
    strOpenArgs = strTechID & "|" & strOccurrenceCt & "|" & strOccurrenceDate

    DoCmd.OpenForm "frmOtherOccurrence", , , , , , strOpenArgs
Else
    Me.OccurrenceAmt = Me.OccurrenceName.Column(1)
    Me.Type = Me.OccurrenceName.Column(2)
End If
End Sub

每次运行时,我都会收到“打开表单操作已取消”,错误代码为2501.它被捕获的行是DoCmd.OpenForm调用。调试不提供其他信息。

以下是OpenArgs传递给的地方:

Private Sub Form_Load()

Dim aryOA As Variant

aryOA = Split(Me.OpenArgs, "|")

Me.lblTechID.Caption = aryOA(0)
Me.lblOccurrenceCt.Caption = aryOA(1)
Me.lblOccurrenceDate.Caption = aryOA(2)

End Sub

1 个答案:

答案 0 :(得分:0)

我不知道这可能是你的问题,但你不能将OpenArgs传递给开放的表单,而打开我的意思是它甚至不能在编辑模式下,应该完全关闭。

否则,表单将打开(将其状态从编辑模式更改为正常),但不会传递OpenArgs,因此OpenArgs将为null并将抛出异常。