I'm not sure whether you have a saved query in Access or SQL in VBA.
But as aytee said "You will have to create the SQL in VBA".....
Originally Posted by
Rpschwar
I'm just wanting a simple command the will show the sql statement like the .sql statement gives you
There is no "simple command". To show the .SQL statement means you are using VBA to get the SQL from a variable in code or from a saved query. Using VBA, you could create a query def object, set the query def object to the saved query, then get the SQL using the .sql property. But it still wouldn't have the actual dates.
You could use the RecordSource property to get the SQL of the saved query - you would/could see the reference to the form/control the date values were taken from, but still wouldn't be able to see anything like
Code:
WHERE (((tblAttendance.RehearsalDate) Between #1/1/2016# And #1/1/2017#))
Originally Posted by
Rpschwar
<snip> If I can run the recordset, why can't I just see the sql string with the parameters replaced?
Because the SQL with the actual date values only exist for a split second. When the query is executed, the SQL is generated, then executed and is gone into the ether. So there is no way to "grab" the SQL that is generated with the dates in the SQL statement for that nano-second that it exists.
And actually you don't "run the recordset". You execute (run) a SQL query that returns a record set object.
Options:
You could hard code the dates in a saved query.... (not very useful IMO)
You could use VBA to modify the SQL of a saved query to set the where condition and use the saved query as the record source for the form/report. (Programmatically hard coding the dates)
You could use a saved query without a where clause, then add a where clause in the OpenForm/OpenReport command (Docmd.OpenReport(ReportName, View, FilterName, WhereCondition, WindowMode, OpenArgs) ) ***** I would use this option.
My $0.02.......