VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Retrieves all entries from a database and populates a listbox. Eg first column in a database is use

by Iain Baughen (2 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 11th May 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Retrieves all entries from a database and populates a listbox. Eg first column in a database is userName, this will fill the list style combo

Rate Retrieves all entries from a database and populates a listbox. Eg first column in a database is use



'Usage:
'replace initializeConnection, closeConnection, initializeRecSet and killRecSet 'with calls to your database connection, disconnection, recordset setup and recordset close functions
        'rssd is the name of the recordset - change this to the name of your recordset
        'collectreference is the column of the databse which is cycled to populate the list.
        'zero is column one, 1 is column two etc,
        

    Public Function populateList(objectRef As Object, tableName As String, collectReference As Integer) As Integer
        On Error Resume Next
        
        Dim intUsers As Integer
        Dim count As Integer
    
        ' where objectReference is the formname.comboboxname.
        'frmEditAccount.cmbEditAcc.Clear
        objectRef.Clear
        resultCode = initializeConnection(dataSource)
        If resultCode <> 0 Then MsgBox "error: connection - returned from function: initializeConnection(from populateList) with return value " & CStr(resultCode)
        resultCode = initializeRecSet
        rsSD.Source = "SELECT * FROM " & tableName
        rsSD.Open
        intUsers = rsSD.RecordCount
         
         If count < rsSD.RecordCount Then
            While count < rsSD.RecordCount
                objectRef.AddItem (rsSD.Collect(collectReference))
                count = count + 1
                rsSD.MoveNext
            Wend
         End If
         
        resultCode = killRecSet
        resultCode = closeConnection(dataSource)
    
   End Function
   

Download this snippet    Add to My Saved Code

Retrieves all entries from a database and populates a listbox. Eg first column in a database is use Comments

No comments have been posted about Retrieves all entries from a database and populates a listbox. Eg first column in a database is use. Why not be the first to post a comment about Retrieves all entries from a database and populates a listbox. Eg first column in a database is use.

Post your comment

Subject:
Message:
0/1000 characters