Passing SQL to QueryDef

G

Guest

I need to be able to build a SQL string dynamically to pass to a querydef.
The string will be based on values chosen from a listbox control and/or other
controls on a form. Any help would be greatly appreciated. Still learning.
 
V

Van T. Dinh

Check Access VB / DAO Help on the "SQL" Property of the QueryDef object.

--
HTH
Van T. Dinh
MVP (Access)


kiloez said:
I need to be able to build a SQL string dynamically to pass to a querydef.
The string will be based on values chosen from a listbox control and/or other
controls on a form. Any help would be greatly appreciated. Still
learning.
 
R

Richard

I need to be able to build a SQL string dynamically to pass to a querydef.
The string will be based on values chosen from a listbox control and/or other
controls on a form. Any help would be greatly appreciated. Still learning.


Dim db as dao.database
Dim strSQL as string

Set db = Currentdb(()

db.QueryDefs("qryYourQuery").SQL = strSQSL




Something like this should do it.



Richard
 
G

Guest

Thanks for the replies so far. I know how to pass the SQL string once it's
built, the problem is building the string dynamically so that for each value
chosen from a given control on a form the SQL string produces a different SQL
string to pass.
 
V

Van T. Dinh

Not sure whether there is a question in your post but you can code something
like:

strSQL = "SELECT * FROM Table1 " & _
" WHERE MyField = " & Me.MyTextBox
qdf.SQL = strSQL
 

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

Top