0

I have a sub-form (it is a continuous form) that was previously bound to a query in an Access database, now I am un-binding all the controls on the form to link the form to a SQL Server database.

There are 3 combo boxes on the form, with the following Row Sources:

  1. Row source type of Value List.
  2. Table/Query.
  3. Value List with Yes or No values.

All 3 combo boxes populate correctly, but when changing the value in Combo box #3, everything freezes, and I have to right click to force the Parent form to close. This does not happen when I change the values in the other two combo boxes.

I have tried changing the number of columns on the combo box from two ("Yes";-1;"No";0) to one ("YES";"NO"), changing the row source type to Table/Query and populating the combo box via a stored procedure, I added the on click event and put a break point within the event. When I change the value, the freeze occurs before entering the on click sub.

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

I encounter this same issue on other sub-forms where there is a Yes/No combo box.

Any help will be appreciated!

braX
  • 11,506
  • 5
  • 20
  • 33
  • First. ADODB provides [parameter](https://stackoverflow.com/questions/10352211/vba-ado-connection-and-query-parameters) that you should use to pass SP arguments!. Any bit-fields on rsYesNo? Show field-types. – ComputerVersteher Sep 04 '19 at 18:31
  • I have used the command and parameter for ADODB, however there is nothing wrong with how the above is coded. rsYesNo returns 2 columns with values Yes, -1 and No, 0. I have changed the stored procedure to return different values. and the form still freezes. – TooOldForThis Sep 04 '19 at 19:37
  • 1
    You don't assign `rsYesNo`, but `rsCmbApplyRatio` to `cboYesNo.Recordset`: `Set Me.cboYesNo.Recordset = rsCmbApplyRatio`. Maybe this causes the issue? What field type is `YesNo` in SQL Server? Try `smallint` instead of a boolean type. – AHeyne Sep 05 '19 at 06:09
  • I have been working on this issue for days, I have tried changing the Row Source Type from "Value List" (Row Source = "YES";-1;"NO";0) changing the column count of the Combobox to 1 and passing 'YES' or 'NO' Back in the stored procedure, or even casting the bit value to an integer and modifying the row source accordingly. In a perfect world, decision be to re-write the front end in VB.net, but this world is not perfect. – TooOldForThis Sep 05 '19 at 14:42
  • Try`"YES";True;"NO";False`as Value-List (Col Count + Bound Col = 2) You recognized @UnhandledException hint to wrong RS assignment (implicating missing`Option Explicit` ) and request to show field-type of`YesNo`(Adodb RS type too) `Click_Event`is very late raised. Events Dirty, Before/AfterUpdate are raised before click. – ComputerVersteher Sep 11 '19 at 02:56

0 Answers0