473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Deleting a table in another MDB

Hello

I can create a table in another database (AnotherMdb) by running the
following SQL from the main database:

SELECT Table1.* INTO NewTable IN "C:/AnotherMdb.mdb" FROM Table1

How would I then delete the NewTable object located in AnotherMdb.mdb from
the main database?

I an using MSAccess 2000

Thanks

G Gerard

Jul 7 '06 #1
7 4019
Greetings,

I was not able to drop a table in a foreign DB using sql, but I was able
to do it using DAO code:
-----------------------------------------------
Dim db As DAO.Database, tdf As TableDef

Set db = DBEngine.OpenDatabase("C:\CodeTest\db2test.mdb")
For Each tdf In db.TableDefs
If tdf.Name = "tblxyz942" Then
db.TableDefs.Delete tdf.Name
Exit For
End If
Next
--------------------------------------------------
HTH,
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jul 7 '06 #2

G Gerard wrote:
Hello

I can create a table in another database (AnotherMdb) by running the
following SQL from the main database:

SELECT Table1.* INTO NewTable IN "C:/AnotherMdb.mdb" FROM Table1

How would I then delete the NewTable object located in AnotherMdb.mdb from
the main database?

I an using MSAccess 2000

Thanks

G Gerard
DBEngine(0)(0).Execute "DROP TABLE [C:\AnotherMdb.mdb].[Table1]"

Jul 7 '06 #3
Rich P <rp*****@aol.comwrote in
news:lO***************@news.uswest.net:
I was not able to drop a table in a foreign DB using sql, but I
was able to do it using DAO code:
-----------------------------------------------
Dim db As DAO.Database, tdf As TableDef

Set db = DBEngine.OpenDatabase("C:\CodeTest\db2test.mdb")
For Each tdf In db.TableDefs
If tdf.Name = "tblxyz942" Then
db.TableDefs.Delete tdf.Name
Exit For
End If
Next
--------------------------------------------------
Why not just do this:

Set db = DBEngine.OpenDatabase("C:\CodeTest\db2test.mdb")
db.TableDefs.Delete "tblxyz942"

Why the For/Each loop?

The only reason I can think of would be to avoid an error, but the
error is easily trapped for.

On the other hand, your method does have the beauty of avoiding
raising an error, which I consider a good thing.

On the issue of DDL, I can't see why you couldn't execute DDL SQL to
drop a table in a foreign database using DAO, or just using an IN
'[database path/name]' clause using the local database object.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jul 7 '06 #4
Yes. I did not try this:

DoCmd.RunSQL "Drop Table [C:\testmdb\db1.mdb].tbl123x"

this did work fine. It was the square brackets that I was missing
earlier.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jul 8 '06 #5
Rich P <rp*****@aol.comwrote in
news:Yi***************@news.uswest.net:
Yes. I did not try this:

DoCmd.RunSQL "Drop Table [C:\testmdb\db1.mdb].tbl123x"

this did work fine. It was the square brackets that I was missing
earlier.
I didn't know that worked! I thought you'd have to use:

Drop Table tbl123x IN 'C:\testmdb\db1.mdb'

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jul 8 '06 #6
I just tried

Drop Table tbl123x IN 'C:\testmdb\db1.mdb'

but did not work. I also tried

Drop Table tbl123x IN [C:\testmdb\db1.mdb]

and

Drop Table tbl123x IN ('C:\testmdb\db1.mdb')

--------------------------------------------------
the only syntax that is working on my workstation is

Drop Table [C:\testmdb\db1.mdb].tbl123x


Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jul 8 '06 #7
Rich P <rp*****@aol.comwrote in
news:N2***************@news.uswest.net:
I just tried

Drop Table tbl123x IN 'C:\testmdb\db1.mdb'

but did not work. I also tried

Drop Table tbl123x IN [C:\testmdb\db1.mdb]

and

Drop Table tbl123x IN ('C:\testmdb\db1.mdb')

--------------------------------------------------
the only syntax that is working on my workstation is

Drop Table [C:\testmdb\db1.mdb].tbl123x
Did you try:

Dim db As DAO.Database

Set db = DbEngine.OpenDatabase("C:\testmdb\db1.mdb")

db.Execute "Drop Table tbl123x", dbFailOnError

db.Close
Set db = Nothing

I can't see why that wouldn't have worked.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jul 9 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: harish | last post by:
DELETING 100 million from a table weekly SQl SERVER 2000 Hi All We have a table in SQL SERVER 2000 which has about 250 million records and this will be growing by 100 million every week. At a...
4
by: Fughal | last post by:
Hi, I have a big DB2 database and I need this database without any Data in it for testing something. I have made a backup of these db and restore it on a testing system. My Problem is now how...
1
by: Mark | last post by:
This question refers to a main form with a continuous form subform. After an error occurs after entering several records in the subform, how can I delete all the data in the main form and all the...
3
by: Nathan Bloom | last post by:
Hi, I have a data entry form (access 2000) that also allows the user to add, update, and delete records from the form. The Delete action is carried out in an event procedure and has the...
1
by: Coy Howe | last post by:
This one seems bizarre! We have a database consisting of a main table and 12 - 15 "sub" tables, which are connected via cascading relationships. The database performs many complex calculations...
46
by: DP | last post by:
hi, i've got a form, with a subform in it. i've got a delete button in the subform. the code i;ve got is; Private Sub cmdDeleteRecord_Click() msg = "Are you sure you want to delete this...
19
by: MaXX | last post by:
Hi, I hope I'm not OT. I have the following issue: I want to delete a record from my db with a php script. Let's say I'm auth'd and I want to delete the record id 440. With a simple form (get...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
9
by: Hamed | last post by:
Hello I have a DataGrid that a is bound to a DataTable. Some of the rows in the DataTable should not be deleted. How can I prohibit deleting of some identified rows? The problem could be...
11
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.