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

Check if objects exist

Status
Not open for further replies.

Spidy6123

Technical User
May 30, 2002
227
CA
Hey guys..

I can't get this to work

it keeps giving me a false..

when I debug.. it crashes here:
Set C = DB.Containers(ObjectNum)
Find_Object = C.Documents(ObjectName$).Name

"Item not found in this collection"
It's something to do with C.Documents... thx guys
 
Nevermind..

just did this


Code:
Function DoesObjectExist(ObjectType$, ObjectName$)
On Error Resume Next

Dim Found_Object, Find_Object As String, ObjectNum As Integer
Dim DB As Database, T As TableDef
Dim Q As QueryDef, C  As Container
Dim Msg As String
Found_Object = -1
Set DB = DBEngine(0)(0)

Select Case ObjectType$
Case "Tables"

    Find_Object = DB.TableDefs(ObjectName$).Name

Case "Queries"

    Find_Object = DB.QueryDefs(ObjectName$).Name

Case Else

Find_Object = DB.Containers(ObjectType$).Documents(ObjectName$).Name

If Err = 3265 Or Find_Object = "" Then
    Found_Object = 0
End If

End Select

DoesObjectExist = Found_Object

End Function
 
Correction:

Code:
Function DoesObjectExist(ObjectType$, ObjectName$)
On Error Resume Next

Dim Found_Object, Find_Object As String, ObjectNum As Integer
Dim DB As Database, T As TableDef
Dim Q As QueryDef, C  As Container
Dim Msg As String
Found_Object = -1
Set DB = DBEngine(0)(0)

Select Case ObjectType$
Case "Tables"

    Find_Object = DB.TableDefs(ObjectName$).Name

Case "Queries"

    Find_Object = DB.QueryDefs(ObjectName$).Name

Case Else

Find_Object = DB.Containers(ObjectType$).Documents(ObjectName$).Name

If Err = 3265 Or Find_Object = "" Then
    Found_Object = 0
End If

End Select

DoesObjectExist = Found_Object

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top