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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dao - ado modify query def

Status
Not open for further replies.

IAMCONFUSED

Programmer
Nov 1, 1999
3
US
My ERP software is dictating that I use ADO connections. I have been able to convert all my code except when I need to modify a querydef. In DAO it was like this:

Sub ReplaceQuery()

Dim dbs As Database, qdf As QueryDef
Set dbs = CurrentDb
dbs.QueryDefs.Refresh

For Each qdf In dbs.QueryDefs
If qdf.Name = "qryMyQuery" Then dbs.QueryDefs.Delete qdf.Name
Next qdf

strSQL = "SELECT * FROM MYDATA;"

Set qdf = dbs.CreateQueryDef("qryMyQuery", strSQL)

DoCmd.OpenQuery qdf.Name, acViewNormal, acReadOnly

Set dbs = Nothing

End Sub


I have simplified my sql statment for demo purposes only, but I need to be able to modify a current query def in access 2000 using vba.

I have looked everywhere for weeks with no solution. If anyone can point me in the right direction, I would very much appreciate it.
 
I found the answer elsewhere and I'm ashamed I overlooked the simple solution. As long as my query is already defined, I can modify as such:

Sub ReplaceQuery()

strSQL = "SELECT * FROM MYDATA;"

CurrentDb.QueryDefs("qryMyQuery").SQL = strSQL

DoCmd.OpenQuery "qryMyQuery", acViewNormal, acReadOnly

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top