View Full Version : delete table in external database


niklas
06-25-2004, 06:01 AM
Hey - need some help...

Have two databases in use, one to store the necessary data, one with user-interface to manage the data. The user-interface keeps only linked tables of the data-db.

It is possible to create new tables in the data-db by running code in the user-interface like:
DoCmd.CopyObject path&name_data-db, table_name, acTable, smple-table_name

It is possibel do create in the user-interface a new link to the table in the data-db by running code in the user-interface like:
set currdbs = CurrentDB
Set tdf = currdbs.CreateTableDef(table_name)
tdf.Connect = ";DATABASE=" & path&name_data-db
tdf.SourceTableName = table_name
currdbs.TableDefs.Append tdf

It is possible for me to delete that link in the user-interface when the new table will not be used anymore, but it is impossible to delete the table in the data-db by running code in the user-interface. I tried code like:
Set dbs = OpenDatabase(path&name_data-db, , False)
DoCmd.DeleteObject acTable, path&name_data-db&table_name

Error message is: Access canīt find the objekt... think I try to delete the table in the user-interface again - not in the data-db

Any help?

ByteMyzer
06-25-2004, 12:25 PM
Try pasting the following text into a new Code Module:

Public Sub TableDelete(Database As String, Table As String)
Dim dbs As Database
Set dbs = OpenDatabase(Database)
dbs.TableDefs.Delete Table
dbs.Close
End Sub


An example call to this Sub:
Call TableDelete("C:\MyDatabase.mdb", "MyTable")

...will delete the table named MyTable from the database C:\MyDatabase.mdb

niklas
06-28-2004, 01:27 PM
Thank you, bytemyzer... now, it works!

Pat Hartman
06-28-2004, 01:50 PM
Database is a data type. I wouldn't use it as a variable name.