VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This code helps u to fill any combobox. One routine fits all

by Per Janssen (3 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 19th January 2005
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This code helps u to fill any combobox. One routine fits all

Rate This code helps u to fill any combobox. One routine fits all



Call FillComboBox(cmbArtist, "Select Artist from Bands", "Artist")

' The subroutine FillCombobox
Public Sub FillComboBox(Comboboxname As ComboBox, SQL As String, Fieldname As String)
    
Dim ado As ADODB.Connection
Dim rsTemp As ADODB.Recordset

Set ado = CreateObject("ADODB.Connection")
ado.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\CDCollectie.mdb;Persist Security Info=False"
    
Set rsTemp = CreateObject("ADODB.Recordset")
        
    With rsTemp
        .LockType = adLockReadOnly
        .CursorType = adOpenForwardOnly
        .Open SQL, ado
    End With
        
    Comboboxname.Clear
        
    Do While Not rsTemp.EOF
        Comboboxname.AddItem rsTemp(Fieldname)
        rsTemp.MoveNext
    Loop
    
rsTemp.Close
Set rsTemp = Nothing

Comboboxname.ListIndex = 0

ado.Close
Set ado = Nothing
    
End Sub

Download this snippet    Add to My Saved Code

This code helps u to fill any combobox. One routine fits all Comments

No comments have been posted about This code helps u to fill any combobox. One routine fits all. Why not be the first to post a comment about This code helps u to fill any combobox. One routine fits all.

Post your comment

Subject:
Message:
0/1000 characters