I Simple want when user click on the combo box .the other corresponding detail should come in a text box.i have written a code but it is not working .Kindly help me.
any help would be Greatly appreciated.here is the code what i have written.

Private Sub CboEmpName_Click() 
Dim con As ADODB.Connection, rs As ADODB.Recordset, sqlQuery As String 
If Not OpenConnection(con) Then 
    MsgBox ("cannot open connection") 
    Set con = Nothing 
    End If 
If CboEmpName.Text <> "" Then 
  Set rs = New ADODB.Recordset 
  rs.Open "Select * from employees where employees.name='" & Trim(CboEmpName.Text) & "'", con, adOpenDynamic, adLockOptimistic 
' TxtPosition.AddItem (rs!Position) 
  TxtPosition.Text = IIf(IsNull(rs!Position), rs!Position, "") 
  End If 
  Call CloseRecordset(rs) 
  Call CloseConnection(con) 
 End Sub

Hi Dear,
There is one this that you could try. Find any event like combo_afterupdate or some thing else which could available from event list and then assign text box value like this:
text1 = combo1.column (1)
text2 = combo1.column (2) .......... and so on.
Just try..........

Hi Dear,
There is one this that you could try. Find any event like combo_afterupdate or some thing else which could available from event list and then assign text box value like this:
text1 = combo1.column (1)
text2 = combo1.column (2) .......... and so on.
Just try..........

Still not working kindly let me know.

Call this my own little quirk but I like to check all three indicators when returning a recordset. (I also for readability like to do it long handed.)

If rs.RecordCount <> 0 And Rs.Bof = False And Rs.Eof = False Then
  TxtPosition.Text = rs.Fields("Position").Value
Else
  TxtPosition.Text = vbNullString
End If

Don't know if changing that will work for you but go ahead and give it a try.


Good Luck

Thank you Vb5 Programmer.Right it is working .here is the code what i have written.

Private Sub CboEmpName_Click()
Dim con As ADODB.Connection, rs As ADODB.Recordset, sqlQuery As String
If Not OpenConnection(con) Then
    MsgBox ("cannot open connection")
    Set con = Nothing
    End If
If CboEmpName.Text <> "" Then
  Set rs = New ADODB.Recordset
  rs.Open "Select * from employees where employees.name='" & Trim(CboEmpName.Text) & "'", con, adOpenDynamic, adLockOptimistic
  TxtPosition.SetFocus
 'TxtPosition.Text = IIf(IsNull(rs!Position), rs!Position, vbNullString)
  TxtPosition.Text = rs!Position & vbNullString
  Exit Sub
   Call CloseRecordset(rs)
  End If
  Call CloseConnection(con)
 End Sub
This question has already been answered. Start a new discussion instead.