Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 4th, 2005, 04:55 PM
Registered User
 
Join Date: Jan 2005
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.

 
Old January 4th, 2005, 05:03 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

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

Mike

Mike
EchoVue.com
 
Old January 5th, 2005, 06:06 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

Can't we make use of TableDef collection?

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
 
Old January 5th, 2005, 07:23 AM
Authorized User
 
Join Date: Jul 2003
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.