Loading

Sunday, March 20, 2011

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

SHARE TWEET

Thank you for reading this article How to load the values of a recordset in a combo box object With URL http://x-tutorials.blogspot.com/2011/03/how-to-load-values-of-recordset-in.html. Also a time to read the other articles.

0 comments:

Write your comment for this article How to load the values of a recordset in a combo box object above!