Deleting objects in another DB

M

Mota

Hello;
How to Delete or Rename a table from another Database (other than the DB im
coding in),while im in the CurrentDB?
Thank you for your help.
 
M

Mota

Ok,then how to delete a table from inside this db.Can i use
DoCmd.DeleteObject and be sure that tables in db will be deleted,rather than
a table with the same name in currentDB?
Thank you for ur help.
 
P

Paul Overway

No, if you use DeleteObject, it will delete from currentdb (or possibly
codedb if you're running the code from an add-in). If you want to delete a
table or a query, Arvin's suggestion will work...

Set db = OpenDatabase("path to database")

db.TableDefs.Delete "some table"
db.QueryDefs.Delete "some query"


HOWEVER, if you're trying to delete a form or any other object other than
tables or queries, you would need to instantiate another Application object
and use automation, i.e.,

Set app = New Access.Application

app.OpenCurrentDatabase "path to database here"

app.Docmd.DeleteObject [objType], [objName]

app.Quit
 
M

Mota

Thank you for ur help.

Paul Overway said:
No, if you use DeleteObject, it will delete from currentdb (or possibly
codedb if you're running the code from an add-in). If you want to delete a
table or a query, Arvin's suggestion will work...

Set db = OpenDatabase("path to database")

db.TableDefs.Delete "some table"
db.QueryDefs.Delete "some query"


HOWEVER, if you're trying to delete a form or any other object other than
tables or queries, you would need to instantiate another Application object
and use automation, i.e.,

Set app = New Access.Application

app.OpenCurrentDatabase "path to database here"

app.Docmd.DeleteObject [objType], [objName]

app.Quit

--
Paul Overway
Logico Solutions
http://www.logico-solutions.com


Mota said:
Ok,then how to delete a table from inside this db.Can i use
DoCmd.DeleteObject and be sure that tables in db will be deleted,rather
than
a table with the same name in currentDB?
Thank you for ur help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top