Deleting newly created QueryDef

  • Thread starter Thread starter NoodNutt
  • Start date Start date
N

NoodNutt

Hi all

Will the following code just remove the newly created QueryDef "qryLHFull"
or will it also delete the data from the original qry "qryLHVol" itself?

Private Sub Report_Close()

Dim dbMyDB As Database, qdMyQuery As QueryDef

Set dbMyDB = DBEngine(0)(0)
Set qdMyQuery = dbMyDB.CreateQueryDef()

qdMyQuery.Name = "qryLHFull"
qdMyQuery.SQL = "DELETE * FROM qryLHVol;"

dbMyDB.QueryDefs.Delete "qryLHFull"
dbMyDB.QueryDefs.Refresh

End Sub

the user will create the query for the report when he/she clicks the CmdBtn
for the report, which works great.

I don't want to nest the new query, once the report is printed & he/she
closes the report, I want to delete the query.

My concern is the line (qdMyQuery.SQL = "DELETE * FROM qryLHVol;")
Will this delete the data in this query, consequently deleteing all the
records in the table it is tied to.

TIA
Mark.
 
All is Kewl.

Thx in advance

I ran it and it all works and nothing that shouldn't be deleted wasn't.

Regards
Mark.
 
Hi Mark

Just a small tip:

You don't need to create and delete a QueryDef to do this. Just execute the
SQL statement:

dbMyDB.Execute "DELETE * FROM qryLHVol;", dbFailOnError
 
Back
Top