VB 6.0 - Display data in database with combobox

In this post we will share VB 6.0 about How to display data in database with combobox. Result of this tutorial when click data in combobox show or display data in database
Please following below :

1. Built database DB.accdb
We have DB.accdb with Table Customer :

2. Open your VB 6.0 application
Design form like below picture
VB 6.0 - Display data in database with combobox
Copy DB.accdb include folder where you crated project VB 6.0
Place below code in form1 :
Dim Conn As New ADODB.Connection
Dim RSCustomer As ADODB.Recordset
Sub FormEmpty()
Text1 = ""
Text2 = ""
Text3 = ""
End Sub
Sub OpenDB()
    Set Conn = New ADODB.Connection
    Set RSCustomer = New ADODB.Recordset
    Conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & App.Path & "\DB.accdb"
End Sub
Private Sub Form_Activate()
 RSCustomer.Open "TBL_CUSTOMER", Conn
    Do Until RSCustomer.EOF
        Combo1.AddItem RSCustomer!Customer_id
End Sub
Private Sub Form_Load()
    Call OpenDB
    Adodc1.ConnectionString = Conn
    Adodc1.RecordSource = "TBL_CUSTOMER"
    Set DataGrid1.DataSource = Adodc1
End Sub
Private Sub Combo1_Click()
    Call OpenDB
    RSCustomer.Open ("Select * From TBL_Customer where Customer_id='" & Combo1 & "'"), Conn
    If Not RSCustomer.EOF Then
        Text1 = RSCustomer!Name
        Text2 = RSCustomer!Address
        Text3 = RSCustomer!Phone
    End If
End Sub

and the last, please run your projec
You can click here to download project / source code above

Subscribe to receive free email updates:

2 Responses to "VB 6.0 - Display data in database with combobox"

  1. bagaimana caranya bu untuk merubah ke versi db mysqlnya bu??
    saya masih agak bingung

    1. Hi Rian,
      Pastikan kamu sudah belajar koneksi database VB 6.0 menggunakan DB MySQL ya, jika sudah tinggal kamu ganti koneksinya aja..
      gampang kan :)