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

Populating a listbox from a parameterized query

P: 6
Hi, I'm having trouble trying to populate a list box with data from a parameterized query.

If I set the rowsource property to the query name, when the form opens I get the parameter values dialog, but I want to pass the params from code.

If I create a querydef, I can pass the parameter in, but I don't know how to get the records into the listbox. I have tried
Expand|Select|Wrap|Line Numbers
  1. lstNames = qdfNames.sql
Expand|Select|Wrap|Line Numbers
  1. lstNames.recordset = qdfNames.OpenRecordset;
Expand|Select|Wrap|Line Numbers
  1. rstNames = qdfNames.OpenRecordset
  2. lstNames = recordSetNames.getRows;
I feel like i'm doing something stupid, coz this should be easy, but I'm too new to access to know all its tricks.

can anyone point me in the right direction?

cheers
Aug 5 '09 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 635
@mcalex
Hi
You have not indicated where/how you are setting the parameters/variable(s) in code, but pehaps you could try something like this
Expand|Select|Wrap|Line Numbers
  1. lstNames.RowSource = "SELECT * FROM qryName WHERE FieldName = " & CodeVariable 
  2. lstNames.Requery
where qryName is the name of the stored querydef which should not have any perameters that you want to set in code.

??


MTB
Aug 5 '09 #2

P: 6
Hi Mike

I was doing something stupid. I hadn't set the RowSourceType property. It seems that as well as the RowSource, access needs to know the type before it will display data in a listbox.

As soon as I added:
Expand|Select|Wrap|Line Numbers
  1. lstNames.RowSourceType = "Table/Query"
it all worked, and nearly exactly how I expected :-)

cheers
Aug 6 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.