Stopping a code to delete a table

D

Don

I've written the following code:

DoCmd.DeleteObject acTable, "tblDATA"
DoCmd.TransferDatabase acImport, "Microsoft Access", Me.PATH_STATEMENT &
"" & Me.FILE_NAME, acTable, "tblDATA", "tblDATA"

This code will delete the table "tblDATA", then go to another database with
an identical table and transfer that "tblDATA" to the original database.

Question: How can I stop this code if the database at the end of the path
statement is not there? The first line of my code deletes the original
"tblDATA" and I'll be left with no table if the second database is not where
it should be. Then, if I do put it where it needs to be, I won't be able to
get by the first line of code when I re-run the code.

I need the code to verify the second database's location and validity before
deleting my table. I'd appreciate anyone's help on this matter. Thanks.
 
D

Douglas J. Steele

Assuming you mean you don't want the delete to happen

If Len(Dir(Me.PATH_STATEMENT & "" & Me.FILE_NAME)) > 0 Then
DoCmd.DeleteObject acTable, "tblDATA"
DoCmd.TransferDatabase acImport, "Microsoft Access", Me.PATH_STATEMENT & _
"" & Me.FILE_NAME, acTable, "tblDATA", "tblDATA"
End If
 
D

Don

Thank you for your response.
--
Don Rountree


Douglas J. Steele said:
Assuming you mean you don't want the delete to happen

If Len(Dir(Me.PATH_STATEMENT & "" & Me.FILE_NAME)) > 0 Then
DoCmd.DeleteObject acTable, "tblDATA"
DoCmd.TransferDatabase acImport, "Microsoft Access", Me.PATH_STATEMENT & _
"" & Me.FILE_NAME, acTable, "tblDATA", "tblDATA"
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top