Dynamic Query

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