[RESOLVED] ListBox to TextBoxes
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:
Private Sub ListBox1_Click()
Dim RS As ADODB.Recordset
Dim CN As ADODB.Connection
CString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\LOMAP\LOMAPMAIN.mdb;"
Set RS = New ADODB.Recordset
Set CN = New ADODB.Connection
CN.ConnectionString = CString
CN.Open
RS.ActiveConnection = CN
RS.Open "SELECT * FROM Clients"
Dim intN As Integer
For intN = ListIndex - 1 To 20
Text1.Text = RS.Fields.Item("ClFName").Value
Text2.Text = RS.Fields.Item("ClLName").Value
Text3.Text = RS.Fields.Item("ClPhone").Value
Text4.Text = RS.Fields.Item("ClFax").Value
Next intN
End Sub