Copy subform into other subform (1 Viewer)

Vulcan1500

Registered User.
Local time
Today, 04:39
Joined
Nov 13, 2007
Messages
143
I have 2 forms and both have a subform. I want to copy the on into the other. The main form is done, but the subform is a problem for me. The problem is that each record of the first sub is copied into the first record of the second. I'm not able to force it to go to the next. This must be done just before rs.MoveNext, but I do not know how. You help is much appreciated.

The code I'm using is:

Code:
Dim rs As DAO.Recordset
Set rs = Forms!frmMainFirst!frmSubFirstl.Form.RecordsetClone
rs.MoveFirst
Do Until rs.EOF
Forms!frmMainSecond!frmSubSecond.Form.Opdracht = rs!Opdracht
Forms!frmMainSecond!frmSubSecond.Form.Prijs = rs!Prijs
Forms!frmMainSecond!frmSubSecond.Form.Aantal = rs!Aantal
Forms!frmMainSecond!frmSubSecond.Form.fkEenheid = rs!fkEenheid
Forms!frmMainSecond!frmSubSecond.Form.Eenheidsprijs = rs!Eenheidsprijs
Forms!frmMainSecond!frmSubSecond.Form.fkDetailBTW = rs!fkDetailBTW
rs.MoveNext
Loop
 

spikepl

Eledittingent Beliped
Local time
Today, 05:39
Joined
Nov 3, 2010
Messages
6,142
Play with the snippets here
Code:
Dim rsTarget as DAO.Recordset
...
Set rsTarget = Forms!frmMainSecond!frmSubSecond.Form.RecordsetClone
...

Do Until rs.EOF
  rsTarget.AddNew
  rsTarget!Opdracht = rs!Opdracht 
   ....
  rsTarget.Update

  rs.MoveNext
...
 

Vulcan1500

Registered User.
Local time
Today, 04:39
Joined
Nov 13, 2007
Messages
143
Thanks for your swift reply Spikelp. I thought that I understood your advice, but now I only see one record in the target and that is empty. Code is:

Code:
Dim rsSource As DAO.Recordset
Dim rsTarget As DAO.Recordset
Set rsSource = Forms!frmOfferteWijzigen!frmOfferteDetail.Form.RecordsetClone
Set rsTarget = Forms!frmNieuweFactuurVanOfferte!frmFactuurDetail.Form.RecordsetClone
Do Until rsSource.EOF
rsTarget.AddNew
rsTarget!Opdracht = rsSource!Opdracht
rsTarget!Prijs = rsSource!Prijs
rsTarget!Aantal = rsSource!Aantal
rsTarget!fkEenheid = rsSource!fkEenheid
rsTarget!Eenheidsprijs = rsSource!Eenheidsprijs
rsTarget!fkDetailBTW = rsSource!fkDetailBTW
rsTarget.Update
rsSource.MoveNext
Loop
 

sakrtwo

New member
Local time
Yesterday, 20:39
Joined
Sep 2, 2015
Messages
7
dear Vulcan1500
thank you sooooooo much i was search for this code more than two weeks
thank you
 

Vulcan1500

Registered User.
Local time
Today, 04:39
Joined
Nov 13, 2007
Messages
143
When I open version 3, go to the form and click 'previous 10' an error is generated. If I understand the code I need to have a counter in each record starting at 1 and each next record goes 1 up. If I add e.g. the customers ID it is likely that gabs are introduced. How can I add such a field in the query?
 

Users who are viewing this thread

Top Bottom