Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Droping table....

Status
Not open for further replies.
Joined
Oct 22, 2001
Messages
215
Location
US
I got the following problem. I have a function that drops the table when I start my project. IF I don't close the project and try to run the same function, it does not see the table and thus, does not drop it. I tried, refresh, save the database, save the table and so forth before exiting the function.... but no luck... What am I doing wrong? TIA --

Function DropTable(ByVal sTableName As String) As Boolean
'Function: DropTable
' Purpose: Drops a table in the current database, if the
' table is found in the tabldefs collection.
Dim db As Database
Set db = DBEngine(0)(0)
' Application.Save
RunCommand acCmdSave
If TableExists(sTableName) Then
db.Execute "Drop Table" & sTableName
End If
DropTable = True
End Function
' Purpose: Determines if a table name is found in the
' Current database's tabledefs collection.
'
'
Function TableExists(ByVal sTableName As String) As Boolean
Dim db As Database, i As Integer
Set db = DBEngine(0)(0)
For i = 0 To db.TableDefs.Count - 1
If "[" & db.TableDefs(i).Name & "]" = sTableName Then
TableExists = True
Exit For
End If
Next
End Function

It look like it does not see the table next time@
 
Function DropTable(i_strTableName as string) as boolean

dim tbl as tabledef

DropTable = False

for each tbl in currentdb.tabledefs
if tbl.name = i_strTableName then
currentdb.tabledefs.delete tbl.name
DropTable = true
exit for
end if
next

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top