Drop query

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
 
W

Wayne-I-M

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
 
D

Dale Fye

You can also use the DeleteObject method

docmd.DeleteObject acQuery, "queryName"

HTH
Dale
 
D

Dale Fye

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top