VBA to Delete Table only if table exists

G

Guest

Hi,

I have VBA code which deletes a table called "Paid Daily". However, in
certain cases, the "Paid Daily" table may not exisit. In order not to
receive an error message, I was thinking of adding an If..Then... statement
to only delete the table if it exists. The problem is that I can seem to get
the code to work.

Here's the code:

If IsEmpty("Table![Paid Daily]") = False Then

DoCmd.DeleteObject acTable = acDefault, "Paid Daily"
Else

<continue with procedure>

Can anyone tell what I'm doing wrong?

Much Appreciated!

Manuel
 
D

Dave Patrick

Try;

DoCmd.SetWarnings False
DoCmd.DeleteObject acTable = acDefault, "Paid Daily"
DoCmd.SetWarnings True

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

:
| Hi,
|
| I have VBA code which deletes a table called "Paid Daily". However, in
| certain cases, the "Paid Daily" table may not exisit. In order not to
| receive an error message, I was thinking of adding an If..Then...
statement
| to only delete the table if it exists. The problem is that I can seem to
get
| the code to work.
|
| Here's the code:
|
| If IsEmpty("Table![Paid Daily]") = False Then
|
| DoCmd.DeleteObject acTable = acDefault, "Paid Daily"
| Else
|
| <continue with procedure>
|
| Can anyone tell what I'm doing wrong?
|
| Much Appreciated!
|
| Manuel
|
 
G

Guest

You can use the error capture to handle this error and continue to the next
line

e.g

Function DeleteTable()
On Error GoTo DeleteTable_Err

DoCmd.DeleteObject acTable = acDefault, "Paid Daily"

Exit Function
DeleteTable_Err:
If Err = 7874 Then
Resume Next
Else
MsgBox Error, Err
End If
End Function
 
G

Guest

Worked beautifully, thanks!

Ofer said:
You can use the error capture to handle this error and continue to the next
line

e.g

Function DeleteTable()
On Error GoTo DeleteTable_Err

DoCmd.DeleteObject acTable = acDefault, "Paid Daily"

Exit Function
DeleteTable_Err:
If Err = 7874 Then
Resume Next
Else
MsgBox Error, Err
End If
End Function
--
\\// Live Long and Prosper \\//
BS"D


Manuel said:
Hi,

I have VBA code which deletes a table called "Paid Daily". However, in
certain cases, the "Paid Daily" table may not exisit. In order not to
receive an error message, I was thinking of adding an If..Then... statement
to only delete the table if it exists. The problem is that I can seem to get
the code to work.

Here's the code:

If IsEmpty("Table![Paid Daily]") = False Then

DoCmd.DeleteObject acTable = acDefault, "Paid Daily"
Else

<continue with procedure>

Can anyone tell what I'm doing wrong?

Much Appreciated!

Manuel
 
Joined
Aug 12, 2016
Messages
1
Reaction score
0
Brother I did it this way
On Error Resume Next-
that DoCmd,setwarnings False wiil not work
 

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