Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax Error In Drop Table Code. 2

Status
Not open for further replies.

lars7

Technical User
Aug 16, 2005
817
GB
Hi Guys,
I would like to delete an import error report table after my spreadsheet is imported but I am getting an syntax error message, can anyone see why?



If TableExists("'Progress to Assim$'_ImportErrors") Then

DoCmd.RunSQL "DROP TABLE 'Progress to Assim$'_ImportErrors; "

Else

'Do Nothing

End If


thanks

tom.

 
It's the single quotes. You need to rename the table to get rid of the error
Code:
If TableExists("'Progress to Assim$'_ImportErrors") Then
    Dim tdf As DAO.TableDef
    Set tdf = Currentdb.Tabledefs("'Progress to Assim$'_ImportErrors") 
    tdf.Name = "TableToDelete"
    Set tdf = Nothing
    DoCmd.RunSQL "DROP TABLE TableToDelete; "
End If
 


Hi Golom,
I got an "Object invalid or no longer set" error message with the code but thanks for the explanation as I used the module below and it works fine.



Function RenameToDelete()
Dim db As DAO.Database


Set db = CurrentDb

Debug.Print

If TableExists("'Progress to Assim$'_ImportErrors") Then

db.TableDefs("'Progress to Assim$'_ImportErrors").Name = "TableToDelete"

DoCmd.RunSQL "DROP TABLE TableToDelete; "

End If


Set db = Nothing

End Function
 
Why not simply this ?
Code:
If TableExists("'Progress to Assim$'_ImportErrors") Then
  db.TableDefs.Delete "'Progress to Assim$'_ImportErrors"
End If

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PH,

that's much simpler
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top