0

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"
    Conn.Open
    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
    RS.MoveNext
    Loop
     
    Set RS = Nothing
    Set Comm = Nothing
    Set Conn = Nothing
    End Sub

Edited by Chhaks: Pasting Code

Attachments upload.jpg 31.74 KB
3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by abu taher
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.