Check for table and delete it with a Macro

Sully38

Board Regular
Joined
Mar 9, 2004
Messages
167
I do not use Macros all that often I need to search for a table existance and if present delete it using only a macro is this possible?
:rolleyes:
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I don't know if you'll be able to do it using a macro.

You could do it using VBA code. Something like this perhaps:

Code:
Function IsTable(tblName As String) As Boolean
' returns true if there is a table called tblName

Dim db As Database
Dim tdf As TableDef

Set db = CurrentDb

    For Each tdf In db.TableDefs
        IsTable = (tdf.Name = tblName)
        If IsTable Then Exit Function
    Next
    
End Function

Sub DeleteMyTable()
    
    If IsTable("MyTable") Then
        DoCmd.DeleteObject acTable, "MyTable"
    End If
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,848
Messages
6,162,406
Members
451,762
Latest member
Brainsanquine

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top