Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 4th, 2005, 04:55 PM
Registered User
Join Date: Jan 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Verifying Table Existence

How would you verify a table exists in an MS Access Project using either a macro or code either as a stored procedure or event. I would prefer to link to a table in a 2nd SQL database, but no simple process for linking in a project, so planning on importing, but have to verify whether table exists or not to do so.

Reply With Quote
  #2 (permalink)  
Old January 4th, 2005, 05:03 PM
Friend of Wrox
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts

I used the code below to determine if the table was present, so I could drop it first, but it should work in your situation as well

Set cn = Application.CurrentProject.Connection
Set rs = New ADODB.Recordset

strSQL = "SELECT Count(*) AS Present FROM MSysObjects WHERE Name = 'tbl_Your_Table_Name_Here' AND Type = 1"

rs.Open strSQL, cn

If rs.Fields("Present") = 1 Then
        'Insert the code needed to execute if table is present
End If

Good Luck


Reply With Quote
  #3 (permalink)  
Old January 5th, 2005, 06:06 AM
Friend of Wrox
Join Date: Dec 2004
Location: Chennai, Tamil nadu, India.
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel

Can't we make use of TableDef collection?

Best Regards

Reply With Quote
  #4 (permalink)  
Old January 5th, 2005, 07:23 AM
Authorized User
Join Date: Jul 2003
Location: Stockton on Tees, , United Kingdom.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts

I use this function fort testing if table exists:

Function Gen_test_if_table_exists(TableName) As Boolean

   Dim tdfLoop
   Gen_test_if_table_exists = False
   With CurrentDb
        'Debug.Print .TableDefs.Count & " TableDefs in " & .Name

        ' Enumerate TableDefs collection.
      For Each tdfLoop In .TableDefs
           'Debug.Print " " & tdfLoop.Name
         If TableName = tdfLoop.Name Then
            Gen_test_if_table_exists = True
            Exit Function
         End If
      Next tdfLoop

    End With

End Function

Cheers Ray
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Check for existence of a cookie GLKGail Classic ASP Basics 0 June 10th, 2008 10:49 AM
Verifying Username/Password...Please wait. cancer10 Classic ASP Databases 0 March 8th, 2007 01:19 AM
Verifying Zip Code Range stevenyoo321 Access VBA 1 February 5th, 2007 08:40 AM
Verifying uploaded File Size in Client-side Ushhh ASP.NET 1.0 and 1.1 Professional 5 August 30th, 2006 07:13 AM

All times are GMT -4. The time now is 07:55 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.