Passing SQL to QueryDef

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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.
 
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
 
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.
 
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
 
Back
Top