Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 2nd, 2008, 08:13 PM
Registered User
 
Join Date: Apr 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Transfer Data from one database (mdb) to another

Hi every one;
I want transfer some data from one database (mdb) to another (also mdb) that update related tables in second database with data from first one. Please help me how can I do that with vba code even any description about the solution would helpful.
Thanks in advance

NazGh
 
Old August 6th, 2008, 07:15 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

You would just need to make a Jet or ADO connection to the other database, and then create a recordset that either updates or inserts your data.

How are you packaging the data that is going to be sent to the other database? Where is the other database? Is it on your LAN? If so, how many database instances will be sending data to the other database (just you, or 100 other users?) Also, will the receiving database be used for transactions in real time other than the ones you are sending? Will you use a DSN?

If you were using a form, for example, and sending a user's first and last names, identifying the record with a PK that was the same in both databases, your code would look something like:

Dim lPK As Long
Dim sLast As String
Dim sFirst As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sSQL As String

lPK = Me.ID
sLast = Me.LastName
sFirst = Me.FirstName

sSQL = "UPDATE tblMyOtherDatabaseTable " & _
       "SET [LastName] = '" & sLast & "', " & _
       "[FirstName] = '" & sFirst & "' " & _
       "WHERE ID = " & lPK

cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=\my_path\MyOtherDatabase.mdb;" & _
        "User ID=userid;" & _
        "Password=password;"

Set rs = New ADODB.Recordset
rs.Open sSQL, cn, adOpenDynamic, adLockOptimistic

'the act of opening the recordset using the connection object updates the database.

So something like this would work. You can also use a DSN and lose some of the connection string.

Did that help?




mmcdonal

Look it up at: http://wrox.books24x7.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to insert an image in a (*.MDB) database thomaz C# 1 May 3rd, 2007 07:02 AM
how to transfer data from excel to Access database swaroop Access VBA 5 April 13th, 2007 09:02 AM
how to transfer data from excel to Access database swaroop Excel VBA 1 April 12th, 2007 10:45 AM
import data from mdb to another mdb mat41 Classic ASP Professional 3 March 9th, 2007 07:01 AM
Can't open .MDB database saxitalis C# 1 November 7th, 2003 04:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.