错误2501 OpenForm操作已取消

时间:2016-11-04 17:10:29

标签: forms vba ms-access runtime-error

我在Access中创建两个表单以用作数据输入表单。两者都是未绑定的。数据是评估“措施”,是我公司遵循的标准的一部分。 “措施”在引号中,因为“措施”通常(被认为并不总是)由多个可报告的值组成(在规范中称为“子措施”)。在这种情况下,我的意图是使用一种形式是输入与“测量”相关的数据部分,而另一种形式则在需要时捕获“子测量”数据。

当我需要捕获与父测量相关的子测量的数据时,计划使用CommandButton来打开子测量表。试图让“添加子测量”按钮工作,但我不断收到标题中提到的错误。

自A)以来,表格是不受约束的。 B)在任何表格中都没有任何数据我不相信腐败是问题(这是this article在RT Error 2501讨论的另一个问题中所链接的内容。)

我也确定在Submeasure Form的Form_Load代码中没有错,因为我在第一行设置了一个断点但在得到错误提示之前没有点击它。

Add Submeasure按钮的代码如下:

Private Sub New_Sub_Click()
'

'Ensure we have a Key for this measure already NOTE: This Key is associated to each 
    submeasure so a ListBox can query for it in a table that holds the submeasure data
    while I'm doing the data entry
If Me.Msr_Key.Value = "" Then
    'notify
    MsgBox "New submeasures cannot be created until a Key has been provided for the parent measure.", vbOKOnly, "Unable to Create Submeasures"

Else
    'Open the form
    DoCmd.OpenForm "New_SubMsr_Form" 'THIS IS THE LINE THAT ERRORS

    'Set the form mode & Parent_Key values
    Forms![New_SubMsr_Form]![Form_Mode].Value = "New"
    Forms![New_SubMsr_Form]![Parent_Key].Value = Me.Msr_Key.Value

    'Hide the Msr Form
    Me.Visible = False
End If

End Sub

New_Msr_Form的完整代码如下:

Option Compare Database

Private Sub Cancel_Btn_Click()
'

'Clear everything and hide form
Me.Msr_Key.Value = Me.Msr_Key.DefaultValue
Me.Measure_Name.Value = Me.Measure_Name.DefaultValue
Me.Spec_Section.Value = Me.Spec_Section.DefaultValue
Me.Spec_Year_Created.Value = Me.Spec_Year_Created.DefaultValue
Me.Complexity.Value = Me.Complexity.DefaultValue
Me.Inc_Amb.Value = Me.Inc_Amb.DefaultValue
Me.Inc_Medicaid.Value = Me.Inc_Medicaid.DefaultValue
Me.Inc_Medicare.Value = Me.Inc_Medicare.DefaultValue

DoCmd.Close acForm, Me.Name
End Sub

Private Sub Form_Load()
'

'Restore defaults
Me.Msr_Key.Value = Me.Msr_Key.DefaultValue
Me.Measure_Name.Value = Me.Measure_Name.DefaultValue
Me.Spec_Section.Value = Me.Spec_Section.DefaultValue
Me.Spec_Year_Created.Value = Me.Spec_Year_Created.DefaultValue
Me.Complexity.Value = Me.Complexity.DefaultValue
Me.Inc_Amb.Value = Me.Inc_Amb.DefaultValue
Me.Inc_Medicaid.Value = Me.Inc_Medicaid.DefaultValue
Me.Inc_Medicare.Value = Me.Inc_Medicare.DefaultValue

End Sub

Private Sub Inc_Amb_Click()

'Update the "CheckBox" value correctly
Call Module1.Check_Uncheck(Me.Inc_Amb)

End Sub

Private Sub Inc_Medicaid_Click()

'Update the "CheckBox" value correctly
Call Module1.Check_Uncheck(Me.Inc_Medicaid)

End Sub

Private Sub Inc_Medicare_Click()

'Update the "CheckBox" value correctly
Call Module1.Check_Uncheck(Me.Inc_Medicare)

End Sub

Private Sub Denom_Only_Click()
'

'Update the "CheckBox" value correctly
Call Module1.Check_Uncheck(Me.Denom_Only)

End Sub

Private Sub Msr_Key_AfterUpdate()
'
Dim RowSrc_Str As String

'Is the field empty?
If Me.Msr_Key.Value = "" Or IsNull(Me.Msr_Key.Value) Then
    'Make sure the row source is empty
    RowSrc_Str = vbNullString
Else
    'Populate the Row source string
    RowSrc_Str = "SELECT Temp_SubMsrs.ID" & _
        "   , Temp_SubMsrs.Submeasure Name" & _
        "   , Temp_SubMsrs.Key" & _
        "   , Temp_SubMsrs.Complexity" & _
        "   , Temp_SubMsrs.Denom_Only" & _
    "FROM Temp_SubMsrs" & _
    "WHERE Temp_SubMsrs.Parent = " & Me.Msr_Key.Value & _
    "ORDER BY Temp_SubMsrs.Submeasure Name;"
End If

'User RowSrc_Str to update the Submeasures field appropriately
Me.Submsrs.RowSource = RowSrc_Str
Me.Submsrs.Requery
End Sub

Private Sub New_Sub_Click()
'

'Ensure we have a Key for this measure already
If Me.Msr_Key.Value = "" Then
    'notify
    MsgBox "New submeasures cannot be created until a Key has been provided for the parent measure.", vbOKOnly, "Unable to Create Submeasures"

Else
    'Open the form
    DoCmd.OpenForm "New_SubMsr_Form"

    'Set the form mode & Parent_Key values
    Forms![New_SubMsr_Form]![Form_Mode].Value = "New"
    Forms![New_SubMsr_Form]![Parent_Key].Value = Me.Msr_Key.Value

    'Hide the Msr Form
    Me.Visible = False
End If

End Sub

来自New_SubMsr_Form的完整VBA在这里:

Option Compare Database

Private Sub Cancel_Btn_Click()
'
'Clear the form
Me.SubMsr_Name.Value = Me.SubMsr_Name.DefaultValue
Me.SubMsr_Key.Value = Me.SubMsr_Key.DefaultValue
Me.Complexity.Value = Me.Complexity.DefaultValue
Me.Denom_Only.Value = Me.Denom_Only.DefaultValue

'Hide the form
Me.Visible = False

'Unhide the Msr Form (if there is one)
If Not (Me.Parent_Key.Value = "" Or IsNull(Me.Parent_Key.Value)) Then
    'Make the form visible
    'Forms![New_Msr_Form].Visible
End If 'else there is no form to make visible

End Sub

Private Sub Denom_Only_Click()
'

'Update the "CheckBox" value correctly
Call Module1.Check_Uncheck(Me.Denom_Only)

End Sub

Private Sub Form_Load()
'

'Make sure the fields start on the correct values
If Me.Form_Mode.Value = "" Or IsNull(Me.Form_Mode.Value) Then
    'First creation, use default values
    Me.SubMsr_Name.Value = Me.SubMsr_Name.DefaultValue
    Me.SubMsr_Key.Value = Me.SubMsr_Key.DefaultValue
    Me.Complexity.Value = Me.Complexity.DefaultValue
    Me.Denom_Only.Value = Me.Denom_Only.DefaultValue
ElseIf Me.Form_Mode.Value = "New" Then
    'Default values
    Me.SubMsr_Name.Value = Me.SubMsr_Name.DefaultValue
    Me.SubMsr_Key.Value = Me.SubMsr_Key.DefaultValue
    Me.Complexity.Value = Me.Complexity.DefaultValue
    Me.Denom_Only.Value = Me.Denom_Only.DefaultValue
Else
    'Update, get correct values
    'Me.SubMsr_Name.Value = access.
    'Me.SubMsr_Key.Value = Me.SubMsr_Key.DefaultValue
    'Me.Complexity.Value = Me.Complexity.DefaultValue
    'Me.Denom_Only.Value =
End If

'Set focus on name
Me.SubMsr_Name.SetFocus

End Sub

Private Sub Save_Btn_Click()
'
Dim Valid_Sub As Boolean
Valid_Sub = False

'Validate that the submeasure is unique


If Valid_Sub Then
    'Create the Temp_SubMsrs record
    DoCmd.OpenQuery Temp_SubMsr_Create

    'Short cut to clearing & exiting SubMsr form is to now invoke Cancel_Click
    'Me.Cancel_Btn.Click
Else
    'Notify user
    MsgBox "temp prompt text", vbOKOnly
End If

End Sub

Check_Uncheck是一个基本上将TextBox变成可扩展的CheckBox的函数(因为原生的CheckBox完全太小)。这是上下文的代码:

Public Sub Check_Uncheck(ByRef TBox As TextBox)
'

'Determine current value
If TBox.Value = "X" Then
    TBox.Value = " "
Else
    TBox.Value = "X"
End If

'Deselect
TBox.SelLength = 0
End Sub

0 个答案:

没有答案