Results 1 to 5 of 5

Thread: Merging 2 databases

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    Slovenia, Europe
    Posts
    66

    Merging 2 databases

    Sorry if this has been asked before but I couldnt found any good reference on this (:

    Lets say we have 2 ms access db. I want to append the second to the first soo all the records of the second db will be at the end of the first and that their indentification number(of the appended records in the first db) will start by the number of the last indentification number of the last record in the first database (sounds funny) How do I do that? I tried numerus things but my attempts were unsuccessful.

    DAO is very simple but this is beyond me for now. I would apprichiate any replies.

  2. #2
    Addicted Member diban's Avatar
    Join Date
    Aug 2002
    Location
    IN
    Posts
    152
    Considering that you have a automatic no. as your id key, try the followihg:
    adocon.execute "Insert into table1(field1,field2, field3,...fieldn)values (select * from table1)".

  3. #3
    Addicted Member diban's Avatar
    Join Date
    Aug 2002
    Location
    IN
    Posts
    152
    adocon.execute "Insert into table1(field1,field2, field3,...fieldn)values (select * from table2)".

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    Slovenia, Europe
    Posts
    66
    Automatic what?The ID field is not set by Auto becuse the ID of the record has to be the same for reference. I have over 40 fields soo... It is messy. I mean like I would say append db2.mdb to db1.mdb... It sound easy but i see it is complicated.

    Thanks....

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    Slovenia, Europe
    Posts
    66
    I got it. It might not be the most effective way but it gets the job done.

    'defenitions of what we are going to use
    'note pb=DB or whatever you want it to name
    Dim pb As Database
    Dim pb1 As Database
    Dim pbset As Recordset
    Dim pbset1 As Recordset
    Dim a As Integer 'we will need this for the ID field
    'NOTE: ID field is not set to Auto

    'opens both the db1(the file we are going to add data to) and db2
    Set pb = OpenDatabase(FileNAme)
    Set pbset = pb.OpenRecordset("table1")
    Set pb1 = OpenDatabase(filename 2)
    Set pbset1 = pb1.OpenRecordset("tavle1")


    pbset.MoveLast 'lets go to the end of our db

    pbset1.MoveFirst 'and at the beggining of this

    Do Until pbset1.EOF 'we are now going to add all the data of the second db to the fist. We will use a simple loop
    With pbset
    a = .Fields("ID") ' We will use this soo the ID field will be ....
    pbset.AddNew ' We will add a new record to the db1


    !ID = a + 1 ' here you can see how the ID fields...
    !Ser1 = pbset1.Fields("Ser1")
    !ser2 = pbset1.Fields("Ser2")
    !ser3 = pbset1.Fields("Ser3")
    !ser4 = pbset1.Fields("Ser4")
    !tock1 = pbset1.Fields("tock1")
    !tock2 = pbset1.Fields("tock2")
    !tock3 = pbset1.Fields("tock3")
    !tock4 = pbset1.Fields("tock4")
    !field= db2 record field' pretty logical what we done
    ' This is very unefficient way ..if you got like over 100 fields

    .Update ' now to update this

    pbset.MoveNext
    pbset1.MoveNext
    End With

    pbset1.MoveNext
    Loop

    'When loop is finished lets close whta we have used
    pbset.Close
    pbset1.Close
    pb.Close
    pb1.Close
    'Enjoy

    Sorry for such bad comments. But it is very easy code soo if I can understand it soo can you!

    If you have any ideas how to solve this problem with less code please post a reply or if you have something else to say.
    Last edited by 3rd_newton_law; Dec 1st, 2002 at 06:28 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width