How to load the values of a recordset in a combo box object


How to load the values of a recordset in a combo box object


Public Sub FillData_ListBox(ByRef lstControl As Object, ByRef strQry As String)
    this routine is used to fill up a list box by passing the lstbox name and
    query
    Dim lstCtrlObj As Object
    Dim Rst As ADODB.Recordset
    On Error GoTo VBError
    Set Rst = New ADODB.Recordset
    With Rst
        .Source = strQry
        .Open , AdoComp, adOpenDynamic, adLockReadOnly
    End With
    Set lstCtrlObj = lstControl
    lstCtrlObj.Clear
    If Rst.EOF = False Then
        Rst.MoveFirst
        While Rst.EOF = False
            lstCtrlObj.AddItem Rst.Fields(1)
            lstCtrlObj.ItemData(lstCtrlObj.NewIndex) = Rst.Fields(0)
            Rst.MoveNext
        Wend
        itsRecCount = 1
        itsProcessClickFlag = True
        lstCtrlObj.ListIndex = 0
    End If

Done:
    Rst.Close
    Set Rst = Nothing
    Exit Sub

VBError: Non-ADO error handler
    DisplayVBError
    GoTo Done
End Sub

Related Posts by Categories

0 komentar:

Posting Komentar