Testing for Existence of Table 
Author Message
 Testing for Existence of Table

The following code gives an error message if the (links to external) tables
referred to in the first 2 lines do not exist .  How can I test to see if
the links do exist so as to bypass the first 2 lines if they don't?

    DoCmd.DeleteObject acTable, "tblSailOrdersView"
    DoCmd.DeleteObject acTable, "tblTaskingsView"
    DoCmd.TransferDatabase acLink, "Microsoft Access",
"H:\Share\Schedul.es\Taskings\SailInstrExport\" & stViewFileName, acTable,
"tblSailOrders", "tblSailOrdersView", False
    DoCmd.TransferDatabase acLink, "Microsoft Access",
"H:\Share\Schedul.es\Taskings\SailInstrExport\" & stViewFileName, acTable,
"tblTaskings", "tblTaskingsView", False



Wed, 26 Feb 2003 03:07:02 GMT  
 Testing for Existence of Table

It's probably simplest just to disable error-handling while you delete the
tables, like this:

    On Error Resume Next
    DoCmd.DeleteObject acTable, "tblSailOrdersView"
    DoCmd.DeleteObject acTable, "tblTaskingsView"
    On Error GoTo 0   'or On Error GoTo MyErrorHandler

--

Dirk Goldgar
(remove NOSPAM from reply address)


Quote:
> The following code gives an error message if the (links to external)
tables
> referred to in the first 2 lines do not exist .  How can I test to see if
> the links do exist so as to bypass the first 2 lines if they don't?

>     DoCmd.DeleteObject acTable, "tblSailOrdersView"
>     DoCmd.DeleteObject acTable, "tblTaskingsView"
>     DoCmd.TransferDatabase acLink, "Microsoft Access",
> "H:\Share\Schedul.es\Taskings\SailInstrExport\" & stViewFileName, acTable,
> "tblSailOrders", "tblSailOrdersView", False
>     DoCmd.TransferDatabase acLink, "Microsoft Access",
> "H:\Share\Schedul.es\Taskings\SailInstrExport\" & stViewFileName, acTable,
> "tblTaskings", "tblTaskingsView", False



Wed, 26 Feb 2003 03:41:50 GMT  
 Testing for Existence of Table

Here is a function you can call if you want to check for the existence of a
table.

Function TableExists(strTableName As String) As Boolean
    On Error Resume Next
    TableExists = IsObject(CurrentDb.TableDefs(strTableName))
End Function
--
Joe
Access MVP
Check out Dev Ashish's web site for answers to common questions
http://www.mvps.org/access/


Quote:
> It's probably simplest just to disable error-handling while you delete the
> tables, like this:

>     On Error Resume Next
>     DoCmd.DeleteObject acTable, "tblSailOrdersView"
>     DoCmd.DeleteObject acTable, "tblTaskingsView"
>     On Error GoTo 0   'or On Error GoTo MyErrorHandler

> --

> Dirk Goldgar
> (remove NOSPAM from reply address)



> > The following code gives an error message if the (links to external)
> tables
> > referred to in the first 2 lines do not exist .  How can I test to see
if
> > the links do exist so as to bypass the first 2 lines if they don't?

> >     DoCmd.DeleteObject acTable, "tblSailOrdersView"
> >     DoCmd.DeleteObject acTable, "tblTaskingsView"
> >     DoCmd.TransferDatabase acLink, "Microsoft Access",
> > "H:\Share\Schedul.es\Taskings\SailInstrExport\" & stViewFileName,
acTable,
> > "tblSailOrders", "tblSailOrdersView", False
> >     DoCmd.TransferDatabase acLink, "Microsoft Access",
> > "H:\Share\Schedul.es\Taskings\SailInstrExport\" & stViewFileName,
acTable,
> > "tblTaskings", "tblTaskingsView", False



Wed, 26 Feb 2003 10:17:11 GMT  
 Testing for Existence of Table
A thing of beauty!  That takes care of a big headache.  Many thanks

Robert

Quote:

>It's probably simplest just to disable error-handling while you delete the
>tables, like this:

>    On Error Resume Next
>    DoCmd.DeleteObject acTable, "tblSailOrdersView"
>    DoCmd.DeleteObject acTable, "tblTaskingsView"
>    On Error GoTo 0   'or On Error GoTo MyErrorHandler

>--

>Dirk Goldgar



Wed, 26 Feb 2003 15:33:07 GMT  
 Testing for Existence of Table

Problem solved!  Much appreciated

Regards

Robert

Quote:

>Here is a function you can call if you want to check for the existence of a
>table.

>Function TableExists(strTableName As String) As Boolean
>    On Error Resume Next
>    TableExists = IsObject(CurrentDb.TableDefs(strTableName))
>End Function
>--
>Joe
>Access MVP
>Check out Dev Ashish's web site for answers to common questions
>http://www.mvps.org/access/



Wed, 26 Feb 2003 15:35:35 GMT  
 Testing for Existence of Table
This reads all the tables and verifies they are valid links.  All you need
to do is replace the

            Dim strFilename As String

            For i = 0 To db.TableDefs.Count - 1
                    Set tbl = db.TableDefs(i)
                    If tbl.Name = strFilename Then
                          'Do your thing
                    End If
            Next i
            Reattach = True
End If

Steve King


Quote:

> The following code gives an error message if the (links to external)
tables
> referred to in the first 2 lines do not exist .  How can I test to see if
> the links do exist so as to bypass the first 2 lines if they don't?

>     DoCmd.DeleteObject acTable, "tblSailOrdersView"
>     DoCmd.DeleteObject acTable, "tblTaskingsView"
>     DoCmd.TransferDatabase acLink, "Microsoft Access",
> "H:\Share\Schedul.es\Taskings\SailInstrExport\" & stViewFileName, acTable,
> "tblSailOrders", "tblSailOrdersView", False
>     DoCmd.TransferDatabase acLink, "Microsoft Access",
> "H:\Share\Schedul.es\Taskings\SailInstrExport\" & stViewFileName, acTable,
> "tblTaskings", "tblTaskingsView", False



Sat, 01 Mar 2003 06:12:04 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Testing for table existence & listing available tables

2. Test for table existence

3. Test for the existence of a table

4. Testing for table existence

5. Testing for table existence

6. Testing for table existence

7. Testing for table existence

8. Testing the existence of a table

9. TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST

10. Testing for existence of a query

11. Testing for a record already in existence

12. test for existence of a field

 

 
Powered by phpBB® Forum Software