Results 1 to 3 of 3

Thread: Another question....

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 1999
    Location
    alb, nm 87112
    Posts
    56

    Post

    What is the easiest way to move records from one table in Access to another using VB6?

  2. #2
    Addicted Member
    Join Date
    Oct 1999
    Posts
    232

    Post

    You can test my function. Place the following Function statement on one, single line.
    Code:
       Function CopyData (from_nm As String, to_nm As String) As Integer
    
          On Error GoTo CopyErr
          Dim ds1 As Dynaset, ds2 As Dynaset
          Dim i As Integer
          Set ds1 = mydb.CreateDynaset(from_nm)
          Set ds2 = mydb.CreateDynaset(to_nm)
          While ds1.EOF = False
             ds2.AddNew
             For i = 0 To ds1.Fields.Count - 1
                ds2(i) = ds1(i)
             Next
             ds2.Update
             ds1.MoveNext
          Wend
          CopyData = True
          GoTo CopyEnd
          CopyErr:
          CopyData = False
          Resume CopyEnd
          CopyEnd:
       End Function
    If you have a big table with a lot of records you can try rename your table to new name and create new table with old name.

    ------------------
    smalig
    [email protected]
    http://vbcode.webhostme.com/

  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    The easiest way is to run an SQL statement:

    Insert Into Table2 Select * From Table1

    Code:
        Dim db As Database
        Dim strSQL As String
    
        On Error Goto ErrHnd
    
        Set db = Workspaces(0).OpenDatabase("C:\MyDB.mdb")
        strSQL = "Insert Into Table2 Select * From Table1"
        db.Execute strSQL, dbFailOnError
    Exit Sub
    
    ErrHnd:
        MsgBox "Error Copying table", vbCritical, "Error Copying Table"
    This code uses DAO, but if you need to use any other Data Access object, you can modify this code an appropriate connection type.

    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]
    ICQ#: 51055819


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