Hi I have an Access project and I need to get the SQL from the queries using code.
I have already managed to get the list of each query in the database - now I need to obtain the SQ behins the query
Code to obtain Queries in database
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData
' Search for open AccessObject objects in AllQueries collection.
For Each obj In dbs.AllViews
strList = strList & obj.Name & ","
Next obj
then I tried the following to get the SQL behind the query
strQuery = Me.cboQuery
Set qryDef = Application.CurrentDb.QueryDefs(strSQuery)
Me.txtSQL = qryDef.SQL
but I get an error Object Variable or With block variable not set
Any ideas?
John
I have already managed to get the list of each query in the database - now I need to obtain the SQ behins the query
Code to obtain Queries in database
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentData
' Search for open AccessObject objects in AllQueries collection.
For Each obj In dbs.AllViews
strList = strList & obj.Name & ","
Next obj
then I tried the following to get the SQL behind the query
strQuery = Me.cboQuery
Set qryDef = Application.CurrentDb.QueryDefs(strSQuery)
Me.txtSQL = qryDef.SQL
but I get an error Object Variable or With block variable not set
Any ideas?
John