My first docmd.runsql

dewsbury

Registered User.
Local time
Today, 01:09
Joined
Jul 4, 2008
Messages
57
I am trying to delete the existing table called "test".
See the last 3 lines of the script below.
(I am showing the full script in the unlikely event that it is relevant).

The "drop table test" is not accepted as a valid command.
It goes yellow in the editor indicating an error.
Why ?

Option Compare Database

Private Sub Command10_Click()
[Mobile] = Forms!Control.[ID]
End Sub

Private Sub Command11_Click()
[Mobile] = [ID]
End Sub

Private Sub Command12_Click()
DoCmd.RunSQL "DROP TABLE test"
End Sub
 
Need quotes around the table name. So, it would be

DoCmd.RunSQL "DROP TABLE 'test'"
 
dewsbury,

Did you have a form open that was bound to table Test?
Other than that, you syntax is OK.

DoCmd.RunSQL "DROP TABLE test"

What was the error message?

Bob,

Good to see you back! I've never used that syntax with the table name
in single-quotes like that. It does work fine without them.

Wayne
 
yes this is fine - just produces a "no such table" message for me

Sub doit()
DoCmd.RunSQL "drop table test"
End Sub

it shouldn't highlight a syntax error though, should it? - it should just run and succeed or run and fail
 

Users who are viewing this thread

Back
Top Bottom