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
 
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
 

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

Back
Top