Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2390
  • Last Modified:

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
0
pbedel
Asked:
pbedel
1 Solution
 
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
 
skeiderCommented:
msdn link is no longer available
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now