Testing for Existence of Table
Author |
Message |
Robert MacMilla #1 / 6
|
 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 |
|
 |
Dirk Goldga #2 / 6
|
 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 |
|
 |
Joe Fallo #3 / 6
|
 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 |
|
 |
Robert MacMilla #4 / 6
|
 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 |
|
 |
Robert MacMilla #5 / 6
|
 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 |
|
 |
Steve Kin #6 / 6
|
 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 |
|
|
|