H
hkgary33 via AccessMonster.com
Dear all,
In a button’s click event, I’ve built a procedure such that once the button
is clicked, a specific query will be run either in Access or Excel. The codes
are as follows:
Dim qdfs As QueryDefs
Dim qdf As QueryDef
Dim dbf As Database
Dim strSQL As String
Set dbf = CurrentDb
Set qdfs = dbf.QueryDefs
strSQL = "SELECT …." ‘ a SQL query statement (details not shown here)
Set qdf = dbf.CreateQueryDef("Query Result", strSQL)
If opt_output = 1 Then 'Option choice that Output to Excel
DoCmd.OutputTo acOutputQuery, qdf.NAME, acFormatXLS, , -1
Else 'Option choice that Output to Access
DoCmd.OpenQuery qdf.NAME
End If
qdfs.Delete qdf.NAME
….
The above codes runs successfully for the first time, but the serious problem
is that once I close the whole mdb file and then launch it in later time, a
pop-up message shown and then the query result won’t be displayed after
clicking the button. The error message said:
“Object ‘Query Result’ already existsâ€
I really don’t know what’s going on, since I’ve already used the Delete
action in the last line of code, so the query should be deleted at last, but
when I switch to the query panel, the “Query Result†query still exists.
Please, can anyone solve this serious problem?
Thanks so much!!!!!
Gary
In a button’s click event, I’ve built a procedure such that once the button
is clicked, a specific query will be run either in Access or Excel. The codes
are as follows:
Dim qdfs As QueryDefs
Dim qdf As QueryDef
Dim dbf As Database
Dim strSQL As String
Set dbf = CurrentDb
Set qdfs = dbf.QueryDefs
strSQL = "SELECT …." ‘ a SQL query statement (details not shown here)
Set qdf = dbf.CreateQueryDef("Query Result", strSQL)
If opt_output = 1 Then 'Option choice that Output to Excel
DoCmd.OutputTo acOutputQuery, qdf.NAME, acFormatXLS, , -1
Else 'Option choice that Output to Access
DoCmd.OpenQuery qdf.NAME
End If
qdfs.Delete qdf.NAME
….
The above codes runs successfully for the first time, but the serious problem
is that once I close the whole mdb file and then launch it in later time, a
pop-up message shown and then the query result won’t be displayed after
clicking the button. The error message said:
“Object ‘Query Result’ already existsâ€
I really don’t know what’s going on, since I’ve already used the Delete
action in the last line of code, so the query should be deleted at last, but
when I switch to the query panel, the “Query Result†query still exists.
Please, can anyone solve this serious problem?
Thanks so much!!!!!
Gary