Hi
As I was concluding the pos , after now checking the actual receipts I was surprised to see that the receipts were coming without details lines. That forced me to use the audit software which revealed the following:
(1) The code below does a good thing to set focus the cursor after inserting a line in the subform and then set focus goes straight in a parent control called txtProductCode that is fine:
Effects or final results in the subform and child table:
(a) No foreign is inserted in the child table leaving the data lines inserted as orphans and no line number also.
As I was concluding the pos , after now checking the actual receipts I was surprised to see that the receipts were coming without details lines. That forced me to use the audit software which revealed the following:
(1) The code below does a good thing to set focus the cursor after inserting a line in the subform and then set focus goes straight in a parent control called txtProductCode that is fine:
Effects or final results in the subform and child table:
(a) No foreign is inserted in the child table leaving the data lines inserted as orphans and no line number also.
Code:
'Parent form VBA code
Public Sub txtProductCode_AfterUpdate()
Dim lngProdID As Long
Dim sReturn$, varValue As Variant
If Not (IsNull(mID)) Then
With Me![sfrmPosLineDetails Subform].Form.RecordsetClone
.AddNew
![ProductID] = mID
![QtySold] = 1
sReturn = DLookup("ProductName & '|' & vatCatCd & '|' & dftPrc & '|' & VAT", _
"tblProducts", _
"BarCode = '" & Me.txtProductCode & "'")
varValue = Split(sReturn, "|")
![ProductName] = varValue(0)
![TaxClassA] = varValue(1)
![SellingPrice] = varValue(2)
![Tax] = varValue(3)
![RRP] = 0
'immediately save the record
.Update
End With
End If
Me.TimerInterval = 100
End Sub
'Subform VBA code
'This is inserted in the control source in order to help create the lines numbering
txtPosition =[Form].[CurrentRecord]
Private Sub Form_BeforeInsert(Cancel As Integer)
'itemesID represents lines numbering in the subform and must be saved on the child table
Me.ItemesID = Me.txtPosition
End Sub