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!

Check of an Object

Status
Not open for further replies.

soupisgood84

Technical User
Apr 17, 2007
45
US
Is there a way I can programmatically check for an object?

My dilemma is, I want to see if a table exists before I give the command to delete it. If I DoCmd.DeleteObject and the table isn't there then I get an error.

Thanks for the help.
 
A useful way is to Dlookup the system table MSysObjects.

Then there is:
Code:
public function FindTableAdo(byval vstrTable as string) as boolean
  dim rs as adodb.recordset
  set rs=currentproject.connection.openschema( _
         adschematables,array(empty,empty,vstrTable))
  FindTableAdo=not rs.eof
  rs.close
  set rs=nothing
end function
 
another way using dao is to check the tabledefs collection. If it is not in the collection then you will throw err 3265

Code:
Public Function isTable(strTbl As String) As Boolean
  On Error GoTo errLbl
  isTable = (CurrentDb.TableDefs(strTbl).Name = strTbl)
  Exit Function
errLbl:
  If Not Err.Number = 3265 Then
    MsgBox Err.Number & " " & Err.Description
  End If
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top