473,394 Members | 1,739 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,394 software developers and data experts.

ADO Copy Table to new MDB Help!

Can ADO be used to insert data into a new table in a new MDB file?

I have tried several things and so far no luck.

Will something like the code below work?

Private Sub Command7_Click()

Dim loConnection As ADODB.Connection

Set loConnection = New ADODB.Connection
loConnection.Open "Provider='Microsoft.JET.OLEDB.4.0';" & _
"Data
Source='F:\DATABASES\NBIMIncome\NBIM_BE.mdb'"
lcSQL = "INSERT INTO t_NBIMFIprebal2 SELECT * FROM "
lcSQL = lcSQL &
"[F:\DATABASES\NBIMIncome\NBIM_BE.mdb].[t_NBIMFIprebal]"""


loConnection.Execute lcSQL, , adExecuteNoRecords
loConnection.Close
Set loConnection = Nothing

End Sub

Nov 13 '05 #1
7 6798
Your code is hard to understand and it contains many errors.
Regardless, I suspect that ADO is not the technology of choice for the
job you describe.

If you were to describe that job more carefully and clearly, I am
guessing that several posters here will have a ready answer.

If there is some requirement that ADO be used, (I cannot imagine what
that could be), please, note that too

Nov 13 '05 #2
I apologise if this appears twice; there a was little problem here when
I thought I had posted before:
It seems ADO can do this (if I understand "this" properly):

Dim c As ADODB.Connection
Dim constr As String
Dim sql As String
Set c = New ADODB.Connection
constr = "PROVIDER=Microsoft.Jet.OLEDB.4.0"
constr = constr & ";DATA SOURCE=C:\Documents and Settings\Lyle
Fairfield\My Documents\Access\db2.mdb"
constr = constr & ";Jet OLEDB:System database=C:\Documents and
Settings\Lyle Fairfield\Application Data\Microsoft\Access\System.mdw"
sql = "INSERT INTO"
sql = sql & vbNewLine & "[C:\Documents and Settings\Lyle Fairfield\My
Documents\Access\tests.mdb].[table1]"
sql = sql & vbNewLine & " SELECT * FROM"
sql = sql & vbNewLine & "[C:\Documents and Settings\Lyle Fairfield\My
Documents\Access\copy of tests.mdb].[table1]"
With c
.Open constr
.Execute sql
End With

But of course, ADO is simply connecting to JET and asking JET to do the
task;

CurrentProject.Connection
CurrentProject.AccessConnection
and
DBEngine(0)(0) can each be used instead of the created ADO connection.

If I had a DAO reference, I would use DBEngine(0)(0) as it may be more
efficient in executing JET queries than ADO connections are.

Nov 13 '05 #3
Well, upon a little testing it seems that ADO can do this (or it can do
what I think your question was):

Dim c As ADODB.Connection
Dim constr As String
Dim sql As String
Set c = New ADODB.Connection
constr = "PROVIDER=Microsoft.Jet.OLEDB.4.0"
constr = constr & ";DATA SOURCE=C:\Documents and Settings\Lyle
Fairfield\My Documents\Access\db2.mdb"
constr = constr & ";Jet OLEDB:System database=C:\Documents and
Settings\Lyle Fairfield\Application Data\Microsoft\Access\System.mdw"
sql = "INSERT INTO"
sql = sql & vbNewLine & "[C:\Documents and Settings\Lyle
Fairfield\My Documents\Access\tests.mdb].[table1]"
sql = sql & vbNewLine & " SELECT * FROM"
sql = sql & vbNewLine & "[C:\Documents and Settings\Lyle
Fairfield\My Documents\Access\copy of tests.mdb].[table1]"
With c
.Open constr
.Execute sql
End With

But of course, ADO is not "doing" anything. It is merely connecting to
JET and asking JET to do it.
DbEngine(0)(0) (assuming a DAO ref) would do it as well and probably
more effciently.
And, of course, CurrentProject.Connection would do it as would
CurrentProject.AccessConnection

Nov 13 '05 #4
thank you.

Nov 13 '05 #5
"lylefair" <ly***********@aim.com> wrote in
news:11**********************@g49g2000cwa.googlegr oups.com:
If I had a DAO reference, I would use DBEngine(0)(0) as it may be
more efficient in executing JET queries than ADO connections are.


DBEngine is a member of the Access Application as well as DAO, and
because of that, you can execute SQL using it without needing a DAO
reference in your database at all.

I just tried it, and it works.

If all you're doing is executing SQL, then you don't need either DAO
or ADO references.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #6

David W. Fenton wrote:
DBEngine is a member of the Access Application as well as DAO, and
because of that, you can execute SQL using it without needing a DAO
reference in your database at all.


Thank you for pointing that out. I was unaware of it.

Nov 13 '05 #7
"lylefair" <ly***********@aim.com> wrote in
news:11**********************@g49g2000cwa.googlegr oups.com:

David W. Fenton wrote:
DBEngine is a member of the Access Application as well as DAO,
and because of that, you can execute SQL using it without needing
a DAO reference in your database at all.


Thank you for pointing that out. I was unaware of it.


This also applies to CurrentDB().

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #8

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

Similar topics

6
by: dev | last post by:
how create a temp table as a copy of a existing table and then update1 field and insert the hole temp table back in the existing table? please any help? if i have 10 fields in 1 record and...
1
by: sbh | last post by:
I need to copy data from a table on one Oracle server to another. Scenario: Need to create a stored procedure in server a, database aa that will copy data from server b, database bb, table bbb to...
19
by: davidgordon | last post by:
Hi, I need some pointers/help on how to do the following if it possible: In my access db, I have the following: Tables: Products, Sub-Assembly, Product-Pack Table, Products
1
by: Knepper, Michelle | last post by:
Hi out there, I'm a first-time user of the "Copy ... From..." command, and I'm trying to load a table from a text flat file. http://www.postgresql.org/docs/7.4/static/sql-copy.html I don't...
2
by: Knepper, Michelle | last post by:
Hi, I'm a first-time user of the "Copy ... From..." command, and I'm trying to load a table from a text flat file. http://www.postgresql.org/docs/7.4/static/sql-copy.html I'm getting the...
4
by: JIM.H. | last post by:
Hello, I am trying to write the data I got from a web service to my table in SQL Server I need to append the dataset wsDS to the dataset ds and do update. PVS.myWS.Loader load = new...
3
by: Swinky | last post by:
I hope someone can help me...I haven't got a clue how to do this. I have a table with several one-to-many relationships. One of the related tables has it's own one-to many relationships as well....
2
by: Swinky | last post by:
I hope someone can help...I feel like I'm walking in the dark without a flashlight (I'm NOT a programmer but have been called to task to do some work in Access that is above my head). I have...
4
by: remya1000 | last post by:
i'm using VB.NET i have 4 computers in network. when i press a button i need to delete a table from computer 2,3,4 and i need to copy that table from computer 1 to 2,3,4. and this file is a...
2
by: froilan03 | last post by:
Hi, Please help me to solve this one. I have page with tables (including hidden tables), my problem is how can I copy both the content of the table. Here is my code snippets: function...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.