Hi there,

I am very new to VB6.
I have a combobox name combo1
textbox= text1
and a database which contain field id and employee name.

what I want is when I click the combo box and select the value 1 the program should look into the database and if it find id=1 then it should automatically display the employee name of that particular ID in the textbox. Can anyone help me.

Private Sub Form_Load()
    Dim RS As ADODB.Recordset
    Dim Conn As ADODB.Connection
    Dim Comm As ADODB.Command
    Dim str As String
    Set Conn = New ADODB.Connection
    Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = employee.mdb"
    Set Comm = New ADODB.Command
    Set Comm.ActiveConnection = Conn
    Comm.CommandText = "SELECT id FROM emp"
    Comm.CommandType = adCmdText
    Set RS = Comm.Execute
    Do Until RS.EOF = True
    Combo1.AddItem RS!id
    Set RS = Nothing
    Set Comm = Nothing
    Set Conn = Nothing
    End Sub

Recommended Answers

All 3 Replies

You can use the sub Combo1_Change to execute the sql statement and place the result in the textbox.

Can you provide me the code please

you can check it. I think you can get idea form it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.