PDA

Click to See Complete Forum and Search --> : Another question....


Dan0331
Dec 9th, 1999, 02:33 AM
What is the easiest way to move records from one table in Access to another using VB6?

smalig
Dec 9th, 1999, 03:13 PM
You can test my function. Place the following Function statement on one, single line.

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
smalig@hotmail.com
http://vbcode.webhostme.com/

Serge
Dec 9th, 1999, 06:06 PM
The easiest way is to run an SQL statement:

Insert Into Table2 Select * From Table1


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
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)