hi, i have a problem that drives me mad since i can't see a mistake and think the code once worked but doesn't anymore (but i am starting to get the impression, that it was a distraction of sense)
Sub COPY()
Set rs1 = CurrentDb.OpenRecordset("SELECT * FROM Working_Table_KAP1") ' opens the recordset1
Set rs2 = CurrentDb.OpenRecordset("SELECT * FROM Duplication_Test") ' opens the recordset2 WHICH IS EMPTY AT THE BEGINNING
If Not rs1.EOF And Not rs2.EOF Then ' dont know why, but some it-experts told me to use that
rs1.MoveFirst
rs2.MoveFirst
Do Until rs1.EOF ' he should run through the whole recordset1
var1 = rs1("KATALOG_ID") ' and put the content of the column KATALOG_ID into var1
var2 = rs1("PROFIL_ID") '...
var3 = rs1("CONCAT")
var4 = rs1("SWERT")
If var2 = 3225 Then ' this is just a test, so he should copy just those cells where PROFIL_ID is 3225 in recordset1
rs2.AddNew ' to add a new row (record) in recordset2
rs2.Fields("PROFIL_ID") = var2 ' copy the content of var1 from recset1 to recset2 into the corresponding column
rs2.Fields("KATALOG_ID") = var1
rs2.Fields("CONCAT") = var3
rs2.Fields("SWERT") = var4
rs2.Update ' to do the job
rs2.MoveNext ' to jump to the next line
End If
rs1.MoveNext
Loop
End If
Set rs1 = Nothing
Set rs2 = Nothing
End Sub
nothing happpens, but the code seems so logical to me and i cant explain what is going wrong (and the most confusing thing is, that i am sure it already worked - but it isnt anymore)
thanks for any kind of recommendation,
stefan
annotation: i am also open to raw sql (in vba) solutions even though i coded it in this dao library, since i do not know (or it is not possible - due to the selection) how to solve such an tast with sql
Sub COPY()
Set rs1 = CurrentDb.OpenRecordset("SELECT * FROM Working_Table_KAP1") ' opens the recordset1
Set rs2 = CurrentDb.OpenRecordset("SELECT * FROM Duplication_Test") ' opens the recordset2 WHICH IS EMPTY AT THE BEGINNING
If Not rs1.EOF And Not rs2.EOF Then ' dont know why, but some it-experts told me to use that
rs1.MoveFirst
rs2.MoveFirst
Do Until rs1.EOF ' he should run through the whole recordset1
var1 = rs1("KATALOG_ID") ' and put the content of the column KATALOG_ID into var1
var2 = rs1("PROFIL_ID") '...
var3 = rs1("CONCAT")
var4 = rs1("SWERT")
If var2 = 3225 Then ' this is just a test, so he should copy just those cells where PROFIL_ID is 3225 in recordset1
rs2.AddNew ' to add a new row (record) in recordset2
rs2.Fields("PROFIL_ID") = var2 ' copy the content of var1 from recset1 to recset2 into the corresponding column
rs2.Fields("KATALOG_ID") = var1
rs2.Fields("CONCAT") = var3
rs2.Fields("SWERT") = var4
rs2.Update ' to do the job
rs2.MoveNext ' to jump to the next line
End If
rs1.MoveNext
Loop
End If
Set rs1 = Nothing
Set rs2 = Nothing
End Sub
nothing happpens, but the code seems so logical to me and i cant explain what is going wrong (and the most confusing thing is, that i am sure it already worked - but it isnt anymore)
thanks for any kind of recommendation,
stefan
annotation: i am also open to raw sql (in vba) solutions even though i coded it in this dao library, since i do not know (or it is not possible - due to the selection) how to solve such an tast with sql