Dynamic Query

B

bressi

I have a report that gathers data from a query. I have a form that
creates an SQL statement dynamically. Does anyone know of a way, within
an event on the form, to apply the SQL statement to the query and popup
the report based on it?


Any help would be greatly appreciated.
 
A

Allen Browne

Would it be possible to do the whole thing in the Open event of the report?

Private Sub Report_Open(Cancel As Integer)
Dim strSql As String
strSQL = "SELECT ...
Me.RecordSource = strSQL
End Sub

If not, or if you are trying to assign a SQL statement for a subreport, you
can write the SQL property of the QueryDef that the report is based on:

Dim strSql As String
strSQL = "SELECT ...
CurrentDb().QueryDefs("Query1").SQL = strSQL
DoCmd.OpenReport "Report1", acViewPreview
 

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