Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21866

Populate ComboBox2 Basen On Text In ComboBox1,With Access DB

$
0
0
My Form:
combo1 (ComboBox)
combo2 (ComboBox)

Database:
ID | Name
1 | one
2 | two
3 | three
4 | four
5 | five
6 | six


So,I want:

If Combo1.Text = "ID" Then
combo2 populate with
1
2
3
4
5
6

ElseIf Combo1.Text = "Name" Then
combo2 populate with
one
two
three
four
five
six

My Code:
Code:

Dim RsClass As New ADODB.Recordset

Private Sub Form_Load()
    conn 'connection from module
    Combo1.AddItem "ID"
    Combo1.AddItem "NAME"
End Sub

Private Sub Combo1_Change()
    RsClass.LockType = adLockOptimistic
    RsClass.CursorType = adOpenDynamic
    If Combo1.Text = "ID" Then
    RsClass.Open "select * from Class", conn, , , adCmdText    'Maybe This Line Wrong?
    If Not RsClass.EOF Then

'Code Here For Populate Combo2 (field ID)

    End If
    ElseIf Combo1.Text = "Name" Then
    RsClass.Open "select * from Class", conn, , , adCmdText      'Maybe This Line Wrong?
    If Not RsClass.EOF Then

'Code Here For Populate Combo2 (field Name)

    End If
End Sub

How To Coding in:
'Code Here For Populate Combo2 (field ID)
'Code Here For Populate Combo2 (field Name)

Viewing all articles
Browse latest Browse all 21866

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>