|
-
Dec 9th, 1999, 03:33 AM
#1
Thread Starter
Member
What is the easiest way to move records from one table in Access to another using VB6?
-
Dec 9th, 1999, 04:13 PM
#2
Addicted Member
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/
-
Dec 9th, 1999, 07:06 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|