我有一个子表单(它是一个连续表单),它以前绑定到 Access 数据库中的查询,现在我取消绑定表单上的所有控件以将表单链接到 SQL Server 数据库。
表单上有 3 个组合框,具有以下行源:
- 的行源类型
Value List
。 Table/Query
.Value List
带有Yes
或No
值。
所有 3 个组合框都正确填充,但是当更改组合框 #3 中的值时,一切都冻结了,我必须右键单击以强制关闭父窗体。当我更改其他两个组合框中的值时,不会发生这种情况。
我尝试将组合框上的列数从两个 ( "Yes";-1;"No";0
) 更改为一 ( "YES";"NO"
),将行源类型更改为Table/Query
并通过存储过程填充组合框,我添加了on click
事件并在事件中放置了一个断点。当我更改值时,冻结发生在进入on click
子之前。
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
我在其他有“是/否”组合框的子表单上遇到了同样的问题。
任何帮助将不胜感激!