Hi Vlad,
I have made some little changes (see my CAPITAL comments in the code) so that process can continue copying into second and the third row. What I did is that I just removed the Else statement after (If lID = lMinID Then) and then I put back extra code to move to next record. This work just fine if I have only one row in VAT form.
However, since I removed ELSE statement the process got stuck when I am in the second row in VAT form. So that would be something like (If lID > lMinID Then….) or that I put back ELSE statement somewhere in the code. I am not sure how and where to put that.
Could you help me please?
So in short: I have current updated code let’s say CODE1 which works fine for first row.
Now I need to put back ELSE statement where the process will continue as written in CODE2 below.
CODE1:
Code:
Private Sub ProcessVAT(lID, lMinID As Long)Dim rs As DAO.Recordset
If lID = lMinID Then 'first record
'1a) Set focus to (first) New record in GL subform
Forms!EntryHead!GeneralLedger.SetFocus
'1b) Copy from Main Form to the first row Record in a subform GL:
Forms!EntryHead.GeneralLedger.Form.Account = Forms!EntryHead.Account
Forms!EntryHead.GeneralLedger.Form.CustCode = Forms!EntryHead.CustCode
Forms!EntryHead.GeneralLedger.Form.Refer = Forms!EntryHead.Refer
Forms!EntryHead.GeneralLedger.Form.Debit = Forms!EntryHead.Debit
Forms!EntryHead.GeneralLedger.Form.Credit = Forms!EntryHead.Credit
Forms!EntryHead.GeneralLedger.Form.Narration = Forms!EntryHead.Narration
'
'HERE I REMOVED "ELSE" STATMENT
'
'1c) Go to next row in a subform GL
Forms!EntryHead.SetFocus
Forms!EntryHead!GeneralLedger.SetFocus
DoCmd.GoToRecord
Set rs = Me.RecordsetClone
rs.Filter = "[ID]" = lID
'3. Copy from Main Form to a subform GL (second record):
'copy from Main Form (Refer, Narration)
Forms!EntryHead.GeneralLedger.Form.Refer = Forms!EntryHead.Refer
Forms!EntryHead.GeneralLedger.Form.Narration = Forms!EntryHead.Narration
'4. Copy from VAT Form (COST+VAT):
If cmbVATtr.Value = 0 Then
'copy from VAT form COST data(account,amount)
Forms!EntryHead.GeneralLedger.Form.Account = rs("ContraAccount") 'Me.ContraAccount
Forms!EntryHead.GeneralLedger.Form.Debit = rs("NetValue00") 'Me.NetValue00
ElseIf cmbVATtr.Value = 1 Then
'copy from VAT form COST data(account,amount)
Forms!EntryHead.GeneralLedger.Form.Account = rs("ContraAccount") 'Me.ContraAccount
Forms!EntryHead.GeneralLedger.Form.Debit = rs("NetValue") 'Me.NetValue
'
'HERE I ADDED THIS:
'
'1c) Go to next row in a subform GL
Forms!EntryHead.SetFocus
Forms!EntryHead!GeneralLedger.SetFocus
DoCmd.GoToRecord
'copy from VAT Form VAT data (VAT acc., VAT amount)
Forms!EntryHead.GeneralLedger.Form.Account = rs("VATAccount") 'Me.VATAccount
Forms!EntryHead.GeneralLedger.Form.Debit = rs("VatValue20") ' Me.VatValue20
ElseIf cmbVATtr.Value = 2 Then
'copy from VAT form COST data(account,amount)
Forms!EntryHead.GeneralLedger.Form.Account = rs("ContraAccount") 'Me.ContraAccount
Forms!EntryHead.GeneralLedger.Form.Debit = rs("NetValue") 'Me.NetValue
'copy from VAT form COST data(account,amount)
Forms!EntryHead.GeneralLedger.Form.Account = rs("ContraAccount") 'Me.ContraAccount
Forms!EntryHead.GeneralLedger.Form.Debit = rs("NetValue") 'Me.NetValue
'copy from VAT Form VAT data (VAT acc., VAT amount)
Forms!EntryHead.GeneralLedger.Form.Account = rs("VATAccount") 'Me.VATAccount
Forms!EntryHead.GeneralLedger.Form.Debit = rs("VatValue10") 'Me.VatValue10
'HERE I ALSO ADDED THIS:
'1c) Go to next row in a subform GL
Forms!EntryHead.SetFocus
Forms!EntryHead!GeneralLedger.SetFocus
DoCmd.GoToRecord
ElseIf cmbVATtr.Value = 9 Then
'copy from VAT form COST data(account,amount)
Forms!EntryHead.GeneralLedger.Form.Account = rs("ContraAccount") 'Me.ContraAccount
Forms!EntryHead.GeneralLedger.Form.Debit = rs("NSV") 'Me.NSV
End If
rs.Close
Set rs = Nothing
End If
End Sub
CODE2:
Code:
'3. Copy from Main Form to a subform GL (second record):
'copy from Main Form (Refer, Narration)
Forms!EntryHead.GeneralLedger.Form.Refer = Forms!EntryHead.Refer
Forms!EntryHead.GeneralLedger.Form.Narration = Forms!EntryHead.Narration
'4. Copy from VAT Form (COST+VAT):
If cmbVATtr.Value = 0 Then
'copy from VAT form COST data(account,amount)
Forms!EntryHead.GeneralLedger.Form.Account = rs("ContraAccount") 'Me.ContraAccount
Forms!EntryHead.GeneralLedger.Form.Debit = rs("NetValue00") 'Me.NetValue00
ElseIf cmbVATtr.Value = 1 Then
'copy from VAT form COST data(account,amount)
Forms!EntryHead.GeneralLedger.Form.Account = rs("ContraAccount") 'Me.ContraAccount
Forms!EntryHead.GeneralLedger.Form.Debit = rs("NetValue") 'Me.NetValue
'1c) Go to next row in a subform GL
Forms!EntryHead.SetFocus
Forms!EntryHead!GeneralLedger.SetFocus
DoCmd.GoToRecord
'copy from VAT Form VAT data (VAT acc., VAT amount)
Forms!EntryHead.GeneralLedger.Form.Account = rs("VATAccount") 'Me.VATAccount
Forms!EntryHead.GeneralLedger.Form.Debit = rs("VatValue20") ' Me.VatValue20
ElseIf cmbVATtr.Value = 2 Then
'copy from VAT form COST data(account,amount)
Forms!EntryHead.GeneralLedger.Form.Account = rs("ContraAccount") 'Me.ContraAccount
Forms!EntryHead.GeneralLedger.Form.Debit = rs("NetValue") 'Me.NetValue
'copy from VAT form COST data(account,amount)
Forms!EntryHead.GeneralLedger.Form.Account = rs("ContraAccount") 'Me.ContraAccount
Forms!EntryHead.GeneralLedger.Form.Debit = rs("NetValue") 'Me.NetValue
'copy from VAT Form VAT data (VAT acc., VAT amount)
Forms!EntryHead.GeneralLedger.Form.Account = rs("VATAccount") 'Me.VATAccount
Forms!EntryHead.GeneralLedger.Form.Debit = rs("VatValue10") 'Me.VatValue10
'1c) Go to next row in a subform GL
Forms!EntryHead.SetFocus
Forms!EntryHead!GeneralLedger.SetFocus
DoCmd.GoToRecord
ElseIf cmbVATtr.Value = 9 Then
'copy from VAT form COST data(account,amount)
Forms!EntryHead.GeneralLedger.Form.Account = rs("ContraAccount") 'Me.ContraAccount
Forms!EntryHead.GeneralLedger.Form.Debit = rs("NSV") 'Me.NSV
End If
rs.Close
Set rs = Nothing
End If
End Sub