Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 2nd, 2008, 08:13 PM
Registered User
 
Join Date: Apr 2008
Location: Toronto, Ontario, Canada.
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
Reply With Quote
  #2 (permalink)  
Old August 6th, 2008, 07:15 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:46 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.