Drop query

  • Thread starter Thread starter navin
  • Start date Start date
N

navin

Hi,

I wanted to know if its possible to drop quries how tables are
dropped, something like Drop query "queryname" or any other way of
doing it through VBA?

i am creating a query with help of querydef and it needs to be deleted
once i am done with my job.

thanks for the help,
navin
 
Hi Navin

You could try something like this - Of course change the names
SomeEventHere - SomeEventOrButton - SomeName


Private Sub SomeEventOrButton_Click()
Dim SomeQueryNameHere As QueryDef
For Each SomeName In CurrentDb.TableDefs
If SomeName.Name = "SomeQueryNameHere" Then
CurrentDb.QueryDefs.Delete SomeName.Name
End If
Next
DoCmd.SetWarnings False

Run the code here

DoCmd.SetWarnings True
CurrentDb.QueryDefs.Delete "SomeQueryNameHere"
End Sub

HTH
 
You can also use the DeleteObject method

docmd.DeleteObject acQuery, "queryName"

HTH
Dale
 
But rather than deleteing and recreating the query, why don't you just keep
it, and modify the querydefs SQL property

This will prevent the file from growing until it is compacted.

Dale
 
Back
Top