How to use a recordset as rowsource for a listbox

Hi,

I am migrating an Access2k app to SQL server. The old app was feeding a list box via VBA in the style :
    query = "SELECT * FROM table"

the WHERE clause is dynamicaly constructed by a function within VBA so that on different events the listbox's rowsource is
    me.listbox.rowsource = query & createwhereclause()

The question is how can I change this in order to have the query executed on the server ?

I would be able to do the same using recordsets by I could not get the rowsource to accept the recordset as valid input.

Thanks for the help,
Pierre
pbedelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ornicarCommented:
I suggest you feed the listbox with a pass-thru query, which you can change programatically.

Something like this:

Dim qd As QueryDef

Set qd = CurrentDb.QueryDef("MyPassThruQuery")

qd.SQL = "Select * from table where ..."

The listbox's rowsource will never change, but you will change the SQL for the query, so you will need to requery the control:

me.listbox.requery

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
skeiderCommented:
msdn link is no longer available
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.