B
blankman via AccessMonster.com
Hi, does anybody know how to delete a table in vba if it exists. See what I
did is, I wrote a funtion that returns a boolean value if it exists or not
and when I'm deleting a table I try to run in the sub procedure but I'm
getting no where.
Here's what I got so far.
1 This funtion returns a boolean value for exitences of table.
Public Function TableExists(TableName As String) As Boolean
' Check to see if Table (TableName) exists and return answer
Dim db As Database ' Any Database
Dim td As TableDef ' Any Table Definition
Set db = CurrentDb ' Get current database
For Each td In db.TableDefs ' Find table
If td.Name = TableName Then ' If table found
TableExists = True ' Signal caller that table
Exit Function ' Back to caller
End If ' If table found
Next td ' Check next table
Set db = Nothing
End Function
2. Then I delete the table if tableexist returns true.
Public Sub DeleteTable(TableName As String)
Dim TableExists As Boolean
Dim db As Database
If TableExists = True Then
DoCmd.DeleteObject acTable, "tbldoor"
End If
End Sub
did is, I wrote a funtion that returns a boolean value if it exists or not
and when I'm deleting a table I try to run in the sub procedure but I'm
getting no where.
Here's what I got so far.
1 This funtion returns a boolean value for exitences of table.
Public Function TableExists(TableName As String) As Boolean
' Check to see if Table (TableName) exists and return answer
Dim db As Database ' Any Database
Dim td As TableDef ' Any Table Definition
Set db = CurrentDb ' Get current database
For Each td In db.TableDefs ' Find table
If td.Name = TableName Then ' If table found
TableExists = True ' Signal caller that table
Exit Function ' Back to caller
End If ' If table found
Next td ' Check next table
Set db = Nothing
End Function
2. Then I delete the table if tableexist returns true.
Public Sub DeleteTable(TableName As String)
Dim TableExists As Boolean
Dim db As Database
If TableExists = True Then
DoCmd.DeleteObject acTable, "tbldoor"
End If
End Sub