Copy form and subform to new from and subform (1 Viewer)

KoskeKos

New member
Local time
Today, 08:17
Joined
May 4, 2021
Messages
28
Helou. Its me again :)

I need to copy form to new form.
Problem is in subform when i have two or more rows of data, I get only one row copied (if is only one row in source sfrm) or last record copied.
How to after loop through fields go to second row on new subform?
Code i got is this:
Code:
Private Sub btnRn2_Click()
Dim strSQL As String
Dim rs As Recordset

'strSQL = "SELECT * FROM p_tbl_RacPPDetail WHERE racunPPnumber = " & Me.RacunPPNumber

'strSQL = "SELECT p_tbl_RacPP.*, p_tbl_RacPPDetail.* " _
& "FROM p_tbl_RacPP INNER JOIN p_tbl_RacPPDetail ON p_tbl_RacPP.RacunPPID = p_tbl_RacPPDetail.RacunPPID;"

strSQL = "SELECT p_tbl_RacPPDetail.[ItemName], p_tbl_RacPPDetail.[ItemCost],p_tbl_RacPPDetail.[Quantity],  " _
& "p_tbl_RacPPDetail.[UnitMeasure], p_tbl_RacPPDetail.[ItemCost] " _
& "FROM p_tbl_RacPPDetail " _
& "WHERE p_tbl_RacPPDetail.RacunPPID = " & Me.RacunPPID

DoCmd.OpenForm "p_frm_Racun", acNormal, , , acFormAdd
   Forms!p_frm_racun!RacunCity = Me!RacunCity
   Forms!p_frm_racun!cmbValuta = Me!cmbValuta
   Forms!p_frm_racun!cmbCurrency = Me!cmbCurrency
   Forms!p_frm_racun!txtRacPPNumber = Me!txtRacPPNumber
   Forms!p_frm_racun!cmbPayMethod = Me!cmbPayMethod
   Forms!p_frm_racun!cmbCustomer = Me!cmbCustomer
   Forms!p_frm_racun!cmbUsluga = Me!cmbUsluga

Set rs = CurrentDb.OpenRecordset(strSQL)
With rs
   If Not .BOF And Not .EOF Then
      .MoveLast
      .MoveFirst
      Do While Not rs.EOF
         'MsgBox rs.Fields("itemname") & " - " & rs.Fields("itemcost")
         Forms!p_frm_racun.frm_Racun_Detail.Form.ItemName = rs.Fields("ItemName")
         Forms!p_frm_racun.frm_Racun_Detail.Form.Quantity = rs.Fields("Quantity")
         Forms!p_frm_racun.frm_Racun_Detail.Form.UnitMeasure = rs.Fields("UnitMeasure")
         Forms!p_frm_racun.frm_Racun_Detail.Form.ItemCost = rs.Fields("ItemCost")
      .MoveNext
      Loop
   End If
.Close
End With
ExitSub:
    Set rs = Nothing
    '..and set it to nothing
    Exit Sub
ErrorHandler:
    Resume ExitSub
End Sub
 
Last edited:

June7

AWF VIP
Local time
Yesterday, 23:17
Joined
Mar 9, 2014
Messages
5,424
Why are you duplicating forms? Are these bound to two different tables?

Make sure focus is on subform container control then go to new record.

Forms!p_frm_racun.frm_Racun_Detail.Setfocus
Docmd.GoToRecord , , acNewRec

Or either open a recordset of the second table and Add records to it or run INSERT action SQL. Requery form Recordset.
 
Last edited:

KoskeKos

New member
Local time
Today, 08:17
Joined
May 4, 2021
Messages
28
Why are you duplicating forms? Are these bound to two different tables?

Make sure focus is on subform container control then go to new record.

Forms!p_frm_racun.frm_Racun_Detail.Setfocus
Docmd.GoToRecord , , acNewRec

Or either open a recordset of the second table and Add records to it or run INSERT action SQL. Requery form Recordset.
Duplicating forms: yes. Its something like: pre-invoice to convert into invoice on click.

And YES! Thats it! Its aLIVE!😱
How can i thank you? :love:🥰
 

Users who are viewing this thread

Top Bottom