list box control - inserting data into columns

S

SirPoonga

I am trying to output some data from a SQL query to a list box control
in Access.

My listbox is named listNames. When I try the following code I get an
error message on the line with '***. The message says "Run-time error
'424' Object Required"


sqlcmd = "SELECT First, Last " & _
"FROM Names"

rs2.Open sqlcmd, CurrentProject.Connection
If Not rs2.EOF Then rs2.MoveFirst
ii = 0
Do While Not rs2.EOF
listNames.Column(0, ii) = rs2.Fields(0) '***
listNames.Column(1, ii) = rs2.Fields(1)
rs2.MoveNext
ii = ii + 1
Loop
rs2.Close
 
A

Andi Mayer

I am trying to output some data from a SQL query to a list box control
in Access.

My listbox is named listNames. When I try the following code I get an
error message on the line with '***. The message says "Run-time error
'424' Object Required"


sqlcmd = "SELECT First, Last " & _
"FROM Names"

rs2.Open sqlcmd, CurrentProject.Connection
If Not rs2.EOF Then rs2.MoveFirst
ii = 0
Do While Not rs2.EOF
listNames.Column(0, ii) = rs2.Fields(0) '***
listNames.Column(1, ii) = rs2.Fields(1)
rs2.MoveNext
ii = ii + 1
Loop
rs2.Close

make first a debug.print rs2.Fields(0)

if this works then it is an error with your listNames
If you expect an answer to a personal mail, add the word "manfred" to the first 10 lines in the message
MW
 
S

SirPoonga

I found out what was going on. Listbox needs to be bound. So I just
figured out a SQL statement to assign tot he row source for what I
needed. Thanks.
 
Top