Error running Delete query

S

Susan L

I created three delete queries, which I wanted to run via a click on the
button. First, when I used the button control wizard, I couldn't see the
queries on the list. Then i created the code (copied and pasted from another
button's code) with the proper name of the button. Now when I test it, I
receive a Label not defined error.

Here's the code:
Private Sub cmdDeleteEXAs_Click()
On Error GoTo Err_cmdDeleteEXAs_Click

Dim stDocName As String

stDocName = "qry_NCC_Exch_Agr_Delete"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_cmdDeleteEXAs_Click:
Exit Sub

Err_cmdDeleteEXAs_Click:
MsgBox Err.Description
Resume Exit_cmdDeleteEXAs_Click

End Sub

The query refers to the correct name of the table targeted for data deletion.
Any thoughts?
 
J

jmonty

Try:
Dim strSQL as string
strSQL = "DELETE FROM [MyTable]" 'Or copy from the SQL view of your query
DoCmd.RunSQL strSQL
 
S

Susan L

That worked. Many thanks.
--
susan


jmonty said:
Try:
Dim strSQL as string
strSQL = "DELETE FROM [MyTable]" 'Or copy from the SQL view of your query
DoCmd.RunSQL strSQL
--

jmonty


Susan L said:
I created three delete queries, which I wanted to run via a click on the
button. First, when I used the button control wizard, I couldn't see the
queries on the list. Then i created the code (copied and pasted from another
button's code) with the proper name of the button. Now when I test it, I
receive a Label not defined error.

Here's the code:
Private Sub cmdDeleteEXAs_Click()
On Error GoTo Err_cmdDeleteEXAs_Click

Dim stDocName As String

stDocName = "qry_NCC_Exch_Agr_Delete"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_cmdDeleteEXAs_Click:
Exit Sub

Err_cmdDeleteEXAs_Click:
MsgBox Err.Description
Resume Exit_cmdDeleteEXAs_Click

End Sub

The query refers to the correct name of the table targeted for data deletion.
Any thoughts?
 
J

John Spencer

Label would normalyy refer to the line labels you have.
Exit_cmdDeleteEXAs_Click:
Err_cmdDeleteEXAs_Click:

You refer to line labels in the On Error line and the Resume line of your
code. The labels and the references to them appear to be correct.

Have you tried to compile your code? If so, what line does it highlight?

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
S

Susan L

Yes, I did compile and it stopped on the first line. What seemed to cure the
ills, was using the strSQL approach, but I had to retype SQL, rather than
paste, and had to be sure to type DoCmd.and let it offer "RunSQL" before it
would work. Just a funny glitch, I suppose.

Thanks.
 

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