[AccessD] Does table exist?

StaRKeY StaRKeY at Wanadoo.nl
Thu Mar 20 15:00:01 CST 2003


Okay, ONE more and then I'll stop... I find this one the shortest and
nicest:-)

Function Exists(str As String) As Boolean
On Error Resume Next
    Exists = (CurrentDb.Containers("Tables").Documents(str).Name = str)
End Function


Good night.

-----Original Message-----
From: accessd-admin at databaseadvisors.com
[mailto:accessd-admin at databaseadvisors.com]On Behalf Of Bobby Heid
Sent: donderdag 20 maart 2003 20:57
To: 'accessd at databaseadvisors.com'
Subject: RE: [AccessD] Does table exist?


Another way that I have not seen here yet is something similar to:

	'this is OTOH
	on error resume next
	if db.tabledefs("tablename").name="" then
	   End If

	if err.number=(can't remember the # right now) then
	   TableExists=FALSE
	   Else
	   	TableExists=TRUE
	   End if

I don't know if this would be any faster, but it only has to look in a
collection, not run a query.

Bobby

-----Original Message-----
From: accessd-admin at databaseadvisors.com
[mailto:accessd-admin at databaseadvisors.com]On Behalf Of t tom
Sent: Thursday, March 20, 2003 2:31 PM
To: accessd at databaseadvisors.com
Subject: Re: [AccessD] Does table exist?


Hi Eric

Sorry,  didn't mean to be persistent  just having fun with this.
Its just that it looks more compact and doesn't use a loop.
Until I came across this code I did use the For Each .....Next construct.

 and thanks gustav,  how about if I rewrite this way

Public Function CheckTableExist (strTableName As String) As Boolean

Dim strCriteria As String
strCriteria = "name = '" & strTableName & "'" & " and (type=1 or type=6)"
CheckTableExist = IIf(DCount("[ID]", "MSysObjects", strCriteria) > 0, True,
False)

End Function


Tomt

_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com


---
Message is tested virus free
Virus Database (VPS): 19-3-2003
Tested on: 20-3-2003 21:53:34

(c) 2000-2003 ALWIL Software.
http://www.avast.com




More information about the AccessD mailing list