Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying records to a new table

Status
Not open for further replies.

henio

MIS
Jun 25, 2003
60
GB
Hi all,

I am trying to copy record a record n times from one table to another where n is a value in that table.

The following code seems to work under Access97 but won't compile under Access2000. It objects to the DAO. in the Dim statements giving a "user-defined type not defined" message.

If I remove the DAO. from those statements, it will compile but I get a runtime error 13 - type mismatch error at the first set statement.

Can anyone please help?
As you experts can probably see, I'm new to this, so any advice would be welcome, including any better ways of achieving this.

Cheers,
Henio

Sub copyfile()
Dim i As Integer
Dim rec1 As DAO.Recordset
Dim rec2 As DAO.Recordset

Set rec1 = CurrentDb.OpenRecordset("Sheet1")
Set rec2 = CurrentDb.OpenRecordset("Sheet2")

Do While rec1.EOF = False

For i = 1 To rec1("Pallet Qty")
rec2.AddNew
rec2("Pallet Number") = rec1("Pallet Number")
rec2("SKU") = rec1("SKU")
rec2("EPM") = rec1("EPM")
rec2("Qty") = rec1("Qty")
rec2("Logical Day") = rec1("Logical Day")
rec2("Quadrant") = rec1("Quadrant")
rec2("Description") = rec1("Description")
rec2("TUC") = rec1("TUC")
rec2("Family Group") = rec1("Family Group")
rec2("Pallet Qty") = rec1("Pallet Qty")

rec2.Update
Next i
rec1.MoveNext
Loop
rec1.Close
rec2.Close
End Sub
 
Hi henio,

Make sure you have Microsoft DAO 3.6 Object Library checked under Tools > References.

Enjoy,
Tony
 
You might want to check the project references and make sure that you've included the correct DAO libraries.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Guys,

thanks for your help. I'd never have found the answer on my own!

Cheers,
Henio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top