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 VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA 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
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 25th, 2005, 10:37 AM
Registered User
 
Join Date: Mar 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Determine if a table exist

Hi! I am creating a database that needs to determine if a certain table already exist or not. How do I do this?

Thank you.

Reply With Quote
  #2 (permalink)  
Old March 25th, 2005, 12:52 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

You can select the table, and see if that results in an error (using the VBA methods to select an item in the database window), or you can loop through the TableDefs collection, checking the name for each item against the name that you are after.
Reply With Quote
  #3 (permalink)  
Old March 25th, 2005, 09:12 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Seattle, WA, .
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
Default

Try something like this:

Code:
If CurrentDb().TableDefs(strTableName).Name = strTableName Then
    ' nop - just doing this if to see if Err 3265 occurs
End If
If Err.Number = 0 then
    ' table exists
ElseIf Err.Number = 3265 Then ' "Item Not Found in the collection"
    ' table does not exist
    Err.Clear
    Debug.Print "table does not exist"
Else
    ' unhandled error
    Err.Raise
End If
Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group
http://www.pnwadg.org
Reply With Quote
  #4 (permalink)  
Old March 27th, 2005, 06:53 AM
Authorized User
 
Join Date: Jul 2003
Location: Stockton on Tees, , United Kingdom.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try the following function - hope it helps

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

Cheers Ray
Reply With Quote
  #5 (permalink)  
Old March 30th, 2005, 04:40 AM
Registered User
 
Join Date: Mar 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi guys! Thanks for the help.
I will try it out.

Have a nice day.

Reply With Quote
Reply


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
Return a record that doesn't exist in a table? Unregistered SQL Server 2000 4 May 3rd, 2006 01:27 AM
Table Exist? elansolutionsltd Access VBA 5 January 23rd, 2006 03:43 AM
Error :Provider (0x80040E37)Table does not exist. thahir Classic ASP Components 0 September 12th, 2005 12:02 AM
Table 'buzzly_comicsite.forum_admin' doesn't exist AMP_Engineer BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 September 17th, 2004 12:01 PM
Table 'buzzly_comicsite.forum_admin' doesn't exist AMP_Engineer BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 September 4th, 2004 06:04 PM



All times are GMT -4. The time now is 05:23 PM.


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