?
Solved

MS Acess 2000 - Delete Object (acTable) and Table does not exist

Posted on 2007-10-01
4
Medium Priority
?
904 Views
Last Modified: 2012-06-21
If the table does not exists I get an error on the delete object - can I check if it exists and if it does then do the delete object?

'Delete Import Table before Linking New SAM Data
DoCmd.DeleteObject acTable, "tbl_Sam_Import_Data"

'The File is linked rather than imported
DoCmd.TransferText acLinkDelim, "SAM Data Import Specification", "tbl_Sam_Import_Data", strImportFileName, False
0
Comment
Question by:Marilync1266
3 Comments
 
LVL 14

Accepted Solution

by:
ragoran earned 1000 total points
ID: 19993916
You can scan the list of tabledefs (currentdb.tabledefs) for one with the appropriate name

dim tb as tabledef
dim wFound as boolean
wFound = false
for each tb in currentdb.tabledefs
   if tb.name = "tbl_Sam_Import_Data" then
      wFound = true
      exit for
   end if
next
if wFound then
   docmd.deleteobject actable, "tbl_Sam_Import_Data"
end if
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 20237904
Here is the Quick-n-Dirty way:
(if you are only concerned about one table)

Sub DeleteTable()
On Error Resume Next
    DoCmd.DeleteObject acTable, "tbl_Sam_Import_Data"
End sub

Basically; If you get an error, it moves on (to the end of the sub, in this case).
If you don't get an error, it deletes the table.

However, you will have to change it to catch the specific error (7874), if you install a more robust error handler.

HTH as well

Jeff Coachman
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20729492
Forced accept.

Computer101
EE Admin
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question