VBA to Delete Table only if table exists

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
|
 
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
 
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
 
Back
Top