What is the easiest way to move records from one table in Access to another using VB6?
Printable View
What is the easiest way to move records from one table in Access to another using VB6?
You can test my function. Place the following Function statement on one, single line.
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.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
------------------
smalig
[email protected]
http://vbcode.webhostme.com/
The easiest way is to run an SQL statement:
Insert Into Table2 Select * From Table1
This code uses DAO, but if you need to use any other Data Access object, you can modify this code an appropriate connection type.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"
------------------
Serge
Software Developer
[email protected]
[email protected]
ICQ#: 51055819