Vba 为什么未绑定的组合框会导致access数据库冻结?

Vba 为什么未绑定的组合框会导致access数据库冻结?,vba,ms-access,combobox,ms-access-forms,Vba,Ms Access,Combobox,Ms Access Forms,我有一个子表单(它是一个连续表单),以前绑定到Access数据库中的查询,现在我取消绑定表单上的所有控件以将表单链接到SQL Server数据库 表单上有3个组合框,具有以下行源: 值列表的行源类型 表格/查询 值列表带有是或否值 所有3个组合框都正确填充,但是当更改组合框#3中的值时,所有内容都会冻结,我必须右键单击以强制关闭父窗体。当我更改其他两个组合框中的值时,不会发生这种情况 我尝试过将组合框上的列数从两个(“Yes”;-1;“No”;0)更改为一个(“Yes”;“No”),将行源类型更

我有一个子表单(它是一个连续表单),以前绑定到Access数据库中的查询,现在我取消绑定表单上的所有控件以将表单链接到SQL Server数据库

表单上有3个组合框,具有以下行源:

  • 值列表的行源类型
  • 表格/查询
  • 值列表
    带有
    所有3个组合框都正确填充,但是当更改组合框#3中的值时,所有内容都会冻结,我必须右键单击以强制关闭父窗体。当我更改其他两个组合框中的值时,不会发生这种情况

    我尝试过将组合框上的列数从两个(
    “Yes”;-1;“No”;0
    )更改为一个(
    “Yes”;“No”
    ),将行源类型更改为
    表/查询
    ,并通过存储过程填充组合框,我添加了单击时的
    事件,并在事件内放置了一个断点。当我更改该值时,在单击输入
    子项之前会发生冻结

    Private Sub Form_Load()
    
        On Error GoTo Err_Handler
    
        Dim strError As String
        Dim lngCompanyID As Long
        Dim lngTabulationID As Long
        Dim dblTtlCEDEPosition As Double
        Dim dblTtlTotalBNTreasury As Double
    
        Dim cnn As ADODB.Connection
        Dim rs As ADODB.Recordset
        Dim rsCmbJob As ADODB.Recordset
        Dim rsCmbClass As ADODB.Recordset
        Dim rsYesNo As ADODB.Recordset
    
        lngTabulationID = KeyTabulationID
        lngCompanyID = mstrCompanyID
    
        Set cnn = New ADODB.Connection
            cnn.Open gconConnectOLEDB
    
        Set rs = New ADODB.Recordset
        With rs
          Set .ActiveConnection = cnn
              .Source = "EXEC spLoadTabulatlatedClassInfo " & lngTabulationID
              .LockType = adLockOptimistic
              .CursorType = adOpenKeyset
              .CursorLocation = adUseClient
              .Open
        End With
        Set rs.ActiveConnection = Nothing
        Set Me.Recordset = rs
    
        Me.txtTabulationID.ControlSource = "TabulationID"
        Me.txtJobID.ControlSource = "JobID"
        Me.txtPlanID.ControlSource = "PlanID"
        Me.cboClass.ControlSource = "Class"
        Me.txtRatio.ControlSource = "Ratio"
        Me.txtVotes.ControlSource = "Votes"
        Me.cboYesNo.ControlSource = "YesNo"
        Me.txtLineItem.ControlSource = "LineItem"
        Me.cboJobName.ControlSource = "JobName"
    
        Set rsCmbClass = New ADODB.Recordset
        With rsCmbClass
          Set .ActiveConnection = cnn
              .Source = "EXEC spLoadClassComboLoad " & lngCompanyID
              .LockType = adLockOptimistic
              .CursorType = adOpenKeyset
              .CursorLocation = adUseClient
              .Open
        End With
        Set rsCmbClass.ActiveConnection = Nothing
        Set Me.cboClass.Recordset = rsCmbClass
    
        '   Set rsYesNo = New ADODB.Recordset
        '   With rsYesNo
        '     Set .ActiveConnection = cnn
        '         .Source = "EXEC uspLoadYesNoCombo"
        '         .LockType = adLockOptimistic
        '         .CursorType = adOpenKeyset
        '         .CursorLocation = adUseClient
        '        .Open
        '   End With
        '   Set rsYesNo.ActiveConnection = Nothing
        '   Set Me.cboYesNo.Recordset = rsCmbApplyRatio
    
    Exit_Handler:
        On Error Resume Next
    
        If LenB(strError) Then
            MsgBox strError, vbCritical, Me.Name & ".FormLoad"
        End If
    
        If Not (rs Is Nothing) Then
           rs.Close
           Set rs = Nothing
        End If
    
        If Not (rsCmbJob Is Nothing) Then
           rsCmbJob.Close
           Set rsCmbJob = Nothing
        End If
    
       If Not (rsCmbClass Is Nothing) Then
          rsCmbClass.Close
          Set rsCmbClass = Nothing
       End If
    
    '   If Not (rsYesNo Is Nothing) Then
    '      rsYesNo.Close
    '      Set rsYesNo = Nothing
    '   End If
    
       If Not (cnn Is Nothing) Then
          If Not (cnn.State = adStateClosed) Then cnn.Close
          Set cnn = Nothing
       End If
    
       Exit Sub
    
    Err_Handler:
        strError = "Error " & Err.Number & ": " & Err.Description
        Resume Exit_Handler
    End Sub
    
    在有“是/否”组合框的其他子表单上,我也遇到了同样的问题


    任何帮助都将不胜感激

    首先。ADODB提供了应用于传递SP参数的参数!。rsYesNo上有位字段吗?显示字段类型。我已经为ADODB使用了命令和参数,但是上面的编码方式没有问题。rsYesNo返回值为Yes,-1和No,0的两列。我已更改存储过程以返回不同的值。表单仍然冻结。您不将
    rsYesNo
    ,而是将
    rscmbappyratio
    分配给
    cboYesNo.Recordset
    Set Me.cboYesNo.Recordset=rscmbappyratio
    。也许这就是问题的根源?SQL Server中的
    YesNo
    字段类型是什么?尝试
    smallint
    而不是布尔类型。我已经研究这个问题好几天了,我尝试将行源类型从“值列表”(Row Source=“YES”;-1;“NO”;0)更改组合框的列计数为1,并将“YES”或“NO”传递回存储过程,甚至可以将位值强制转换为整数,并相应地修改行源。在一个完美的世界里,我们决定在VB.net中重新编写前端,但这个世界并不完美;是的;“不”;False
    作为值列表(Col Count+Bound Col=2),您识别出@UnhandledException提示错误的RS赋值(暗示缺少
    选项Explicit
    ),并请求显示
    的字段类型no
    (Adodb RS类型也是)
    单击\u事件
    很晚才引发。单击之前会引发更新前/更新后的脏事件。