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

How to test whether a table exists

Status
Not open for further replies.

DwayneS

Instructor
Mar 29, 2002
70
I have to import dozens of spool files, some of which are pretty messy. All of them result in import errors and I was using a simple line of code to delete all the error tables.

Suddenly one out of a hundred files does NOT generate an error table and the code crashed. I tried to add a simple If to test for the existence of the table and it won't work. I've tried everything I know and can't get it. Anybody have a minute to fix my glitch?

Here's the piece of code that won't work.
==============


Do While FileIn <> ""
GetFile = DataPath & FileIn
ErrTable = Left(FileIn, Len(FileIn) - 4) & "_ImportErrors"
DoCmd.TransferText acImportFixed, "FACSIn", "tGetDate", GetFile, False, ""

'==== This is the If that's not working

If TableExists(ErrTable) Then
DoCmd.DeleteObject acTable, ErrTable
End If

'=========

FileIn = Dir
Loop


Dwayne Streeter, CPA, CITP
 

Check this thread705-1322390, there is a TableExist Function there!
 
'=====
On Error Resume Next
DoCmd.Close acTable, ErrTable, acSaveNo
DoCmd.DeleteObject acTable, ErrTable
'=====

should work...
Why check if it exists since you're anyway going to delete it? Just ignore errors that occur.

The key to it is the On Error Resume Next line, so it's high time you looked into Error Handling.

HTH

[pipe]
Daniel Vlas
Systems Consultant

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top