I'm using VB6 and an Access 2003 database.

The database has a table named Clients that contains first name, last name, phone number, and fax number.

On my form I have a ListBox which I have filled with the last name (ClLName) field from the database and several empty TextBoxes.

When I click on the last name in the ListBox I would like to populate the TextBoxes with first name, last name, phone number and fax number that correspond to the last name selected in the ListBox.

My ListBox is populated with code in the form load event and that works fine.
The code below doesn't work to populate the TextBoxes. All I am getting is the information for the last record in the database.

I am sure this is pretty simple, but I can't seem to make it work.

I would appreciate any help you can give.

Thanks

VB Code:
  1. Private Sub ListBox1_Click()
  2.     Dim RS As ADODB.Recordset
  3.     Dim CN As ADODB.Connection
  4.    
  5. CString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  6.           "Data Source=C:\LOMAP\LOMAPMAIN.mdb;"
  7.  
  8. Set RS = New ADODB.Recordset
  9. Set CN = New ADODB.Connection
  10. CN.ConnectionString = CString
  11. CN.Open
  12. RS.ActiveConnection = CN
  13. RS.Open "SELECT * FROM Clients"
  14.  
  15. Dim intN As Integer
  16. For intN = ListIndex - 1 To 20
  17.  
  18. Text1.Text = RS.Fields.Item("ClFName").Value
  19. Text2.Text = RS.Fields.Item("ClLName").Value
  20. Text3.Text = RS.Fields.Item("ClPhone").Value
  21. Text4.Text = RS.Fields.Item("ClFax").Value
  22.  
  23. Next intN
  24.  
  25. End Sub