Are you wanting to:
a) view the results of the query, or
b) just programmatically examine the query records in your code.
For (a) create a dummy query for viewing, and assign its SQL property. For
example, say you create any old query and name it qry2C, then instead of the
Execute line use:
CurrentDb.QueryDefs("qry2C").SQL = strSQL
DoCmd.OpenQuery "qry2C"
If (b), use OpenRecordset, and you can loop through the records. Here's an
example:
http://allenbrowne.com/func-DAO.html#DAORecordsetExample
Note that the Forms! bit will need modifying for OpenRecordset: concatenate
the value into the string:
" WHERE (((FloatTable.DateAndTime) > " & _
Format([Forms]![form1]![Text6], "\#mm\/dd\/yyyy\#") & _
") And (FloatTable.TagIndex) = 0) "+ _
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Reply to group, rather than allenbrowne at mvps dot org.
R Vaughn said:
Would you mind providing additional advice? I tried the following code
and
triggered a 3065 (cannot run a Select query) message. I also tried the
Docmd.runSQL "..." approach with no luck.
Set db = CurrentDb
Set qdf = db.QueryDefs("Query1")
strSQL = "SELECT FloatTable.DateAndTime," + _
" FloatTable.TagIndex, TagTable.TagName, FloatTable.Val" + _
" FROM FloatTable INNER JOIN TagTable ON FloatTable.TagIndex
=TagTable.TagIndex" + _
" WHERE (((FloatTable.DateAndTime) > [Forms]![form1]![Text6]) And
(FloatTable.TagIndex) = 0) "+ _
"ORDER BY FloatTable.TagIndex;"
CurrentDb.QueryDefs("Query1").Execute
End Sub
Allen Browne said:
A generic routine to pull a SQL statement apart is messy (e.g. Access
allows
fields called Where, or there could be nested WHERE clauses in
subqueries.)
My preference is to build the SQL statement in code, and then assign it
to
whatever.
This may help take a sample SQL statement from SQL View of a query into
your
VBA code:
http://allenbrowne.com/ser-71.html
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Reply to group, rather than allenbrowne at mvps dot org.
My objective is to use visual basic to add a criterion to the query
language, to more easily change the criterion's value. I am a novice
in
this
area and have looked at other related postings but am still struggling.
Would you mind providing some suggestions, especially for using a
subroutine
that would append a value from a control (in a form) to the criteria
list
in
the SQL?
.
.