By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,824 Members | 2,410 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,824 IT Pros & Developers. It's quick & easy.

How to display a query in a list box using a record set?

P: n/a
Can someone help? I need to execute
strSQL = "SELECT * FROM qry_viewFDOExport" when a button is pressed and
the results displayed in a list box.

I want to do something like
Dim db As Database
Dim rs As Recordset
Set rs = db.OpenRecordset(strSQL) etc and then loop through all the
results but I'm getting my head all mixed up with all the different ways
of opening/creating a recordset.
Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Jan 16 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
jim Bob wrote:
Can someone help? I need to execute
strSQL = "SELECT * FROM qry_viewFDOExport" when a button is pressed
and the results displayed in a list box.

I want to do something like
Dim db As Database
Dim rs As Recordset
Set rs = db.OpenRecordset(strSQL) etc and then loop through all the
results but I'm getting my head all mixed up with all the different
ways of opening/creating a recordset.
Thanks.

*** Sent via Developersdex http://www.developersdex.com ***


Why don't you just use...

Me!ListBoxName.RowSource = "SELECT * FROM qry_viewFDOExport"
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Jan 16 '06 #2

P: n/a

Because I want to get the connection going. My goal is to try to allow
the user to build the sql on the form and therefore create a custom
query so they can export whatever column they want to excel.
*** Sent via Developersdex http://www.developersdex.com ***
Jan 16 '06 #3

P: n/a
jim Bob wrote:
Because I want to get the connection going. My goal is to try to allow
the user to build the sql on the form and therefore create a custom
query so they can export whatever column they want to excel.
*** Sent via Developersdex http://www.developersdex.com ***


I don't follow. What does displaying a query result in a ListBox have to do
with "exporting a column to Excel"?
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Jan 16 '06 #4

P: n/a
Sorry, my mistake.
I just want to allow the user to enter some text, check a few boxes etc
and then be able generate a query, and output the results to a listbox.

I can build the required SQL statement from the form. I'm just unsure
how to open a recordset, pass the sql through, read through all the rows
and output it to the listbox.

Cheers.

*** Sent via Developersdex http://www.developersdex.com ***
Jan 16 '06 #5

P: n/a
Go back to Rick's first reply. He showed you exactly how to do it. Just
construct the SQL and set it as the RowSource for the ListBox. There is no
need to create a recordset or iterate through rows.

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.
"jim Bob" <fr****@gmail.com> wrote in message
news:QK***************@news.uswest.net...
Sorry, my mistake.
I just want to allow the user to enter some text, check a few boxes etc
and then be able generate a query, and output the results to a listbox.

I can build the required SQL statement from the form. I'm just unsure
how to open a recordset, pass the sql through, read through all the rows
and output it to the listbox.

Cheers.

*** Sent via Developersdex http://www.developersdex.com ***


Jan 16 '06 #6

P: n/a

Ah, just pass the variables from the form straight to the query
itself....

So simple that I over looked it. Doh!
Thanks guys!
*** Sent via Developersdex http://www.developersdex.com ***
Jan 16 '06 #7

P: n/a

Ah, just pass the variables from the form straight to the query
itself....

So simple that I over looked it. Doh!
Thanks guys!
*** Sent via Developersdex http://www.developersdex.com ***
Jan 16 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.