?
Solved

Querying 2 different databases.

Posted on 2004-04-05
6
Medium Priority
?
166 Views
Last Modified: 2010-05-02
I have 2 MS-Access databases, one that is 180 megs and grows weekly, includes all data for the entire South Area. The other one I want to bring in the records from the 1st DB that meet a certain requirement such as MU = 650 - 675.. This would greatly reduce the overall size of the table and allow quicker reporting. The question is how do I write the code to query one database and insert that data into the other database with VB?
0
Comment
Question by:tkrpata
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 19

Expert Comment

by:Shauli
ID: 10758716
INSERT INTO target [IN externaldatabase] [(field1[, field2[, ...]])]
SELECT [source.]field1[, field2[, ...]
FROM tableexpression

S
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 10758742
Create 2 connections.  Select a recordset from the first using your criteria disconnect the recordset, then connect it to the table in the second database.

Leon
0
 
LVL 11

Expert Comment

by:jmwheeler
ID: 10758747
Add a reference to your project (Project -> References) 'Microsoft ActiveX Data Objects 2.? Library'.  Then you can connect do db's using ADO
Private db1 As New ADODB.Connection
Private db2 As New ADODB.Connection
Private rs1 as New ADODB.Recordset
Private rs2 as New ADODB.Recordset
Private db1Path As String
Private db2Path As String
Private sql as string

db1Path = (enter path of db1 in " ")
db2Path = (enter path of db2 in " ")
db1.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & db1Path & ";"
db2.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & db2Path & ";"

sql = "SELECT * FROM tablename WHERE MU>=650 AND MU<=675"              'replace tablename with the name of the table the records are in
rs1.open sql, db1

Do While Not rs1.EOF
    sql = "INSERT INTO tablename (field1name, field2name) VALUES (" & _                        'replace tablename with the name of the table the records are in
                  rs1![Field1] & "," & rs![Field2] & ")"                                                              'if you are inserting data into a number field this is fine, if you inserting
    rs2.Open sql, db2                                                                                                      'data into a text field use '     ex.  " ' " & rs![Field1] & " ',' "       etc.
    rs1.MoveNext
Loop

0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 11441207
PAQed - no points refunded (of 250)

modulo
Community Support Moderator
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month15 days, 3 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question