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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I drop a table if it exists? 2

Status
Not open for further replies.

crystalreporting

Instructor
Feb 13, 2003
649
NZ
I've tried the macro 'deleteobject' function, but it returns an error message if the table is not present in the database. I've tried SQL e.g.

IF EXISTS( SELECT *
FROM MSYSOBJECTS
WHERE (((MSYSOBJECTS.Name)='CREXPORT')))
DROP TABLE CREXPORT

But this gives me an error if I use it in a SQL query, or as a macro using RunSQL.

The table is an export from Crystal Reports and I'd like to have it deleted if it exists when the main form is opened.

Thanks - Peter.

Peter Shirley
 
Try this code in the OnOpen event of your main form...

Code:
If IsObject(CurrentDb.TableDefs("CREXPORT")) Then
    DoCmd.RunSQL "DROP TABLE CREXPORT"
End If
 
VBA code closest to your SQL:
Code:
If Not IsNull(DLookUp("Name", "MSYSOBJECTS", "Name='CREXPORT'")) Then
  DoCmd.RunSQL "DROP TABLE CREXPORT"
End If

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top