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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does TableDef exist or not? 4

Status
Not open for further replies.

biot023

Programmer
Nov 8, 2001
403
GB
Hallo.
I was just wondering if there's a function or something that tells you whether a particular (temporary) tabledef exists at the moment or not.
Or, if not, if there's a safe way of calling delete on it that doesn't blow up when the table no longer exists.

Any help very gratefully appreciated. If it don't make you laugh, it ain't true.
 
Try just trapping the error. Step through the code to make it "blow uo" and get the error. Include err trap in the code. Check for the object doed not exist err when you attempt to delete the table.

On the other hand, why delete the table? Just empty it w/ a Delete * From sometable. That should not cause an error.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
This'll do it...
If DCount("*", "msysobjects", "name=TableName") > 0 Then DoCmd.DeleteObject acTable, "TableName"
 
if the error occurs while trying to create the new temp table i woul suggest you to use adox to re-create it
here is the code
Option Compare Database
Option Explicit

Public Sub createTbl()
'=================================================================================
'create table from userID procedure from nt
'=================================================================================


Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table


Set tbl = New ADOX.Table
Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection

'=================================================================================
'check existance and delete
'=================================================================================

On Error Resume Next
cat.Tables.Delete "tablename"
'=================================================================================
'create table
'=================================================================================

tbl.name = "tablename"
With tbl.Columns
.Append "ID", adInteger
.Append "name", adVarWChar, 20
.Append "surname", adVarWChar, 20
End With

With cat.Tables
.Append tbl
.Refresh
End With

Application.RefreshDatabaseWindow

Set cat = Nothing
Set tbl = Nothing



End Sub
 
Try this one, perhaps place it in a global module.

Function Table_isThere(Tbl2Find as String) As Integer
'see if 'Tbl2Find' exists
'returns True if there, False if not
Dim MyDB As Database, I As Integer
Set MyDB = CurrentDB
For I = 0 To MyDB.TableDefs.Count - 1
If MyDB.TableDefs(I).Name = Tbl2Find Then
Table_isThere = True
Exit For
End If
Next I
End Function

Bruce Gregory
 
fulkeel, that is exactly what I was looking for.
Thanks alot, man!

Douglas JL If it don't make you laugh, it ain't true.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top