A
annysjunkmail
Hi Group,
Could someone advise me if the following is possible.
I have designed a mini reporting system to record queries/sql that I
run on a database. I have done this as I am asked to run numerous
queries each day and it is not manageable to store them all in the
query window. The sql of each query is stored in a table called
'tblDatabaseQueriesSearchMethods' (there are about 600 stored in my
database so far).
It actually works very well but I have one problem. For example, lets
say I designed a query, stored the sql and was asked to revisit it, but
then was asked to change or update the criteria...I then open it in
design view (using the attached code below), make the necessary
changes, but am forced to copy and paste the new sql back over the old
sql to store my new sql. Is there any clever way to automatically
update my sql with the new sql without the need for copying and pasting
(which I and others sometimes forget to do and we find it a clumsy way
of doing things). I could send a someone a slimmed copy of the
database to provide a working example if would help
(Hope this reads right btw)
Many thanks
Tony
here's the code that call the design view which allows me to make my
changes...)credit to Duane Hookum)
'View the query
'Trap the error if MyQuery exists
On Error GoTo cmdReport_Click_Err
Dim strSQL As String 'Basic SQL String
Dim strQueryName As String
Dim qdf As DAO.QueryDef
Dim db As DAO.Database
Set db = DBEngine.Workspaces(0).Databases(0)
strSQL = Forms![frmDatabaseReports]![txtSQL]
strQueryName = "MyQuery"
Set qdf = db.CreateQueryDef(strQueryName, strSQL)
db.QueryDefs.Refresh
'DoCmd.OpenQuery "MyQuery", acViewDesign
DoCmd.OpenQuery (strQueryName), acViewDesign
Set qdf = Nothing
db.Close
Set db = Nothing
cmdReport_Click_Exit:
On Error Resume Next
Exit Sub
'This rotuine traps the error if MyQuery exists
'and deletes it if it does
cmdReport_Click_Err:
If Err = 3012 Then 'MyQuery wasn't delete from previous usage
db.QueryDefs.Delete "MyQuery"
Resume
Else
MsgBox Err & ": " & Error$, 16, "Error in cmdReport_Click"
Resume cmdReport_Click_Exit:
End If
Could someone advise me if the following is possible.
I have designed a mini reporting system to record queries/sql that I
run on a database. I have done this as I am asked to run numerous
queries each day and it is not manageable to store them all in the
query window. The sql of each query is stored in a table called
'tblDatabaseQueriesSearchMethods' (there are about 600 stored in my
database so far).
It actually works very well but I have one problem. For example, lets
say I designed a query, stored the sql and was asked to revisit it, but
then was asked to change or update the criteria...I then open it in
design view (using the attached code below), make the necessary
changes, but am forced to copy and paste the new sql back over the old
sql to store my new sql. Is there any clever way to automatically
update my sql with the new sql without the need for copying and pasting
(which I and others sometimes forget to do and we find it a clumsy way
of doing things). I could send a someone a slimmed copy of the
database to provide a working example if would help
(Hope this reads right btw)
Many thanks
Tony
here's the code that call the design view which allows me to make my
changes...)credit to Duane Hookum)
'View the query
'Trap the error if MyQuery exists
On Error GoTo cmdReport_Click_Err
Dim strSQL As String 'Basic SQL String
Dim strQueryName As String
Dim qdf As DAO.QueryDef
Dim db As DAO.Database
Set db = DBEngine.Workspaces(0).Databases(0)
strSQL = Forms![frmDatabaseReports]![txtSQL]
strQueryName = "MyQuery"
Set qdf = db.CreateQueryDef(strQueryName, strSQL)
db.QueryDefs.Refresh
'DoCmd.OpenQuery "MyQuery", acViewDesign
DoCmd.OpenQuery (strQueryName), acViewDesign
Set qdf = Nothing
db.Close
Set db = Nothing
cmdReport_Click_Exit:
On Error Resume Next
Exit Sub
'This rotuine traps the error if MyQuery exists
'and deletes it if it does
cmdReport_Click_Err:
If Err = 3012 Then 'MyQuery wasn't delete from previous usage
db.QueryDefs.Delete "MyQuery"
Resume
Else
MsgBox Err & ": " & Error$, 16, "Error in cmdReport_Click"
Resume cmdReport_Click_Exit:
End If