listbox layout, oh so close

50ld13r

Registered User.
Local time
Today, 01:11
Joined
Jun 2, 2006
Messages
23
I have been wresting with populating my list box and now its working however the layout isnt quite what i want.
So far the layout is below

1234
jones
5678
smith

i want it to be

1234 jones
5678 smith

so each row of associated date is on one line

the code im current using is below:

Private Sub cmdFind_Click()

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim phone As Integer
phone = txtPhoneNum
Dim sqlCustomer As String
Dim n As Integer

Set db = CurrentDb()

sqlCustomer = "SELECT * FROM [tblCustomers] WHERE [PhoneNum] LIKE '" & Me.txtPhoneNum & "*'"

Set rs = db.OpenRecordset(sqlCustomer, dbOpenDynaset)

Do Until rs.EOF = True

lstRecords.AddItem rs.Fields("intAccNum")
lstRecords.AddItem rs.Fields("strName")
rs.MoveNext

Loop

rs.Close
Set rs = Nothing
db.Close
Set db = Nothing

End Sub

thanks for your help in advance
 
I'm curious why you don't just use an SQL statement as the source of the listbox? It can have a WHERE clause that restricts it similar to your recordset. In fact, you could simply set the rowsource of it to your sqlCustomer variable. You'd have to change the row source type to Table/Query. You'd also want to adjust the SQL to just pull the 2 fields.
 

Users who are viewing this thread

Back
Top Bottom