Modify stored query using VBA

acidtechno

New member
Local time
Today, 09:32
Joined
May 24, 2007
Messages
9
Is it possible to modify stored query using VBA?
 
OK I found a solution, for all of you who need this:

Add ADOX referrence to the project.

Code:
    Dim cn As ADODB.Connection
    Dim catDB As ADOX.Catalog
    Dim cmd As ADODB.Command
    Dim sQueryName As String
    Dim sSQL As String
   
    Set cn = CurrentProject.Connection
    Set catDB = New ADOX.Catalog
   
    catDB.ActiveConnection = cn
   
    sQueryName = "MyQuery"
    sSQL = "SELECT ID FROM Customers"
    
    Set cmd = New ADODB.Command
    Set cmd = catDB.Procedures(sQueryName).Command
    cmd.CommandText = sSQL
   
    Set catDB.Procedures(sQueryName).Command = cmd
   
    Set catDB = Nothing
    cn.Close
 

Users who are viewing this thread

Back
Top Bottom