pedie
Well-known Member
- Joined
- Apr 28, 2010
- Messages
- 3,875
Hi everyone!
I think i have posted here too many times now....however i really do need help on this so please dont mind...
I have 2 table with same fields..
Fields are qt1, Q2,Attac which is Attachment field. I want to move all records including attachements in records to the new table...
How can I modify this code to work with my table...
Thanks in advance for helping...
Regards
Pedie
I think i have posted here too many times now....however i really do need help on this so please dont mind...
I have 2 table with same fields..
Fields are qt1, Q2,Attac which is Attachment field. I want to move all records including attachements in records to the new table...
How can I modify this code to work with my table...
Thanks in advance for helping...
Regards
Pedie
Code:
[FONT=Courier New]Set rstFrom = dbs.OpenRecordset("SELECT [Risk Assessment and Area Classification].* FROM [Risk Assessment and Area Classification] " & _
"WHERE ((([Risk Assessment and Area Classification].ProjectRef)= '" & targetProjectRef & "'))" & _
"ORDER BY [Risk Assessment and Area Classification].[Installation ID]", dbOpenSnapshot)[/FONT]
[FONT=Courier New]Set rstTo = dbs.OpenRecordset("Risk Assessment and Area Classification", dbOpenDynaset)[/FONT]
[FONT=Courier New]rstFrom.MoveFirst
Do Until rstFrom.EOF[/FONT]
[FONT=Courier New]rstTo.AddNew
For iFor = 1 To rstFrom.Fields.Count - 1 ' use 1 not 0 as has ID field is Autonumber[/FONT]
[FONT=Courier New]If rstFrom.Fields(iFor).Type <> 104 And rstFrom.Fields(iFor).Type <> 109 Then ' types 104 and 109 are Multi-Value field[/FONT]
[FONT=Courier New]If rstTo.Fields(iFor).Name = "ProjectRef" Then
rstTo.Fields(iFor).Value = myProjectRef
Else
rstTo.Fields(iFor).Value = rstFrom.Fields(iFor).Value
End If[/FONT]
[FONT=Courier New]Else
Set rstMVFrom = rstFrom.Fields(iFor).Value[/FONT]
[FONT=Courier New]If rstMVFrom.RecordCount > 0 Then
Set rstMVTo = rstTo.Fields(iFor).Value[/FONT]
[FONT=Courier New]Do While rstMVFrom.EOF = False
rstMVTo.AddNew
rstMVTo.Fields(0).Value = rstMVFrom.Fields(0).Value
rstMVTo.Update
rstMVFrom.MoveNext
Loop
rstMVFrom.Close
rstMVTo.Close
End If ' rstFrom[/FONT]
[FONT=Courier New]End If ' iFor
Next iFor[/FONT]
[FONT=Courier New]rstTo.Update[/FONT]
[FONT=Courier New]rstFrom.MoveNext
Loop ' rstFrom[/FONT]
[FONT=Courier New]rst2.Close
Set rst2 = Nothing
[/FONT]