Change Query SQL Programatically

  • Thread starter Thread starter AlCamp
  • Start date Start date
A

AlCamp

I need to change the SQL statement for a saved query "on the fly".
I'd be using the OnOpen event of a report, if that's possible.

I checked out the properties for queries, and can't seem to find anything to
hang my hat on.

Is this possible? Could someone get me going in the right direction, or
refer me to information as to how this might be done?

Thanks,
Al Camp
 
Try something like this:
CurrentDb.QueryDefs("MyQuery").SQL = "SELECT * FROM MyTable;"

Of couse, you could also set the RecordSource of the report itself in its
Open event:

Private Sub Form_Open(Cancel As Integer)
Me.RecordSource = "SELECT * FROM MyTable;"
End Sub
 
Back
Top