Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing a query SQL programatically

Status
Not open for further replies.

VBAguy22

IS-IT--Management
Aug 5, 2003
180
CA
Hello,
I have a query, say [myQuery]. And I composed an SQL string myString.
Is there a function to change the sql code in myQuery to myString from whatever it is now programatically. I am aware of CurrentDb.CreateQueryDef(), but this function creates a new query, I just need to change the sql.
 
How about:
Code:
Dim qdf As DAO.QueryDef

Set qdf = CurrentDb.QueryDefs("myQuery")
qdf.SQL = "Select * from tblTable"
 
Try:
Code:
Dim dbs as DAO.Database
Dim qdf as DAO.QueryDef

Set dbs = CurrentDb()
Set qdf = dbs.QueryDefs("qryYourQuery")

qdf.SQL = "SELECT blah blah blah"
Make sure you have references to Microsoft DAO Object Library.

-Pete
 
Sorry remou. Posted 1 minute later...was still typing while you were posting. jinx



-Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top