Change Query SQL Programatically

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
 
A

Allen Browne

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
 
J

John Vinson

I need to change the SQL statement for a saved query "on the fly".

In what way? If you're just changing criteria, or the Order By clause,
you can use a Paramter query. Are you changing other aspects of the
query? If so, what?

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
Top