Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / January 2008

Tip: Looking for answers? Try searching our database.

Table exist

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jeanulrich00@gmail.com - 14 Jan 2008 19:05 GMT
Hi

A simple question

On a form, I have a button that create a table when someone click on
it "DoCmd.open query  "
But I want to add something that will stop the code if the table
already exist

Something like

If  the table exist  then
msgbox "The table already exist"
else
DoCmd.open query "...."

So what is the right sentence for "if the table exist"

thanks
John - 14 Jan 2008 19:26 GMT
You could use for instance the following function:

Public Function tableExists(strTableName As String) As Boolean
Dim dbClient As Database
Dim tdf As TableDef
Set dbClient = CurrentDb

For Each tdf In dbClient.TableDefs
   If tdf.Name = strTableName Then
       tableExists = True
       Exit Function
   End If
Next
tableExists = False
End Function

You can call the function like this:

If tableExists("YourTableName") = True Then
   MsgBox "Yes, it exists."
Else
   MsgBox "No, it does not exist."
End If

john

> Hi
>
[quoted text clipped - 15 lines]
>
> thanks
Douglas J. Steele - 14 Jan 2008 19:32 GMT
If IsNull(DLookup("Name", "MSysObjects", _
 "Name='xxxx' And Type IN (1,4,6)")) Then
 DoCmd.open query "...."
Else
 MsgBox "The table already exist"
End If

Replace xxxx with the name of the table (remember to include the single
quotes)

MSysObjects is a system table that exists in all databases (it's normally
hidden). Type 1 refers to tables in the current database, type 4 refers to
tables linked using ODBC, type 6 refers to all other linked tables.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Hi
>
[quoted text clipped - 15 lines]
>
> thanks
Krzysztof Pozorek [MVP] - 14 Jan 2008 19:52 GMT
1. TableDefs collection (...)

2. MSysObjects table (...)

3. And one more possibility:
Dim Table_exists As Boolean
WizHook.Key = 51488399
Table_exists = WizHook.GetCurrentView("Table1")

K.P. MVP, Poland
www.access.vis.pl

> Hi
>
[quoted text clipped - 15 lines]
>
> thanks
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.