Add subform rows to another subform, based on Date

Add subform rows to another subform, based on Date

I've a pretty complicated flow to build, hope someone want to help me.

I have 2 forms, the New_Retail_Order (form1) and Credit_Card_Expenses (form2) and 2 subforms, Products (sub1) and Orders (sub2).

Every time I add a record in form1, if Payment_Method = "Credit Card", a new record in form2 has to be created, and all the products added in sub1 have to be added in sub2.

Moreover, when I add a second record in form1, the process repeats, BUT, if there is already a record in form2 for that given month, rows of sub1 have to be added to the current sub2 (which was already created), instead if it's a new month a new record has to be created.

Let me try with an example:

I create 3 records in Retail Orders (form1):

-record 1: order date-13/06; 3 products(sub1) A,B and C
-record 2: order date 25/06; 1 product(sub1) E
-record 3: order date 3/07; 2 products(sub1) D and F

the result should be that 2 records in Credid_Card_Expenses (form2) are created:

-record 1: accounting date (month + year of referred retail orders) 06/19; 4 products(sub2) A, B, C and E
-record 2: accounting date 07/19; products D and F

Hope to have been clear enough.

Thank you in advice for the help!