Dynamic query parameters

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

Got controls with a Rowsource using a select statement, the where clause of
the select statement should use a variable existing in code.
Whats the syntax for writing this
Quick sample:

Dim Myvar as string
Myvar = "abcd"
Say the variable setting above was public in scope and declared well before
the form using it is called.
select * from mytable where myfield = "abcd" what I would think to be the
final result sql statement

What should I write in the Rowsource of the control? I dont want parameter
question boxes to pop up. I just want the control to gran the variable and
use it automatically.


Thanks for any help

Bob
 
You could rewrite the Row Source using code.

Me.MyControl.RowSource = "select * from mytable where myfield = """ & MyVar
& """"

This will concatenate in the value of MyVar and place double quotes around
it.

You could also place the value of the variable in a table created just for
this purpose then the SQL statement could find it using a DLookup function.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top