D
dave
I have a main form that displays a subform in continuous form mode. The
amount textboxes (txtAmt) in the individual records on the subform should
sum up to the amount on the main form (txtGTotal). If they do not, I need
to alert the user before moving off the record.
I created a hidden text box (txtSumAmt) on the subform that sums the
individual txtAmt text boxes. I can compare this to txtGTotal on the main
form but I have two problems.
1. I don't know the event that triggers when the user moves off the current
record.
2. I tried coding the onCurrent event of the main form with this:
Private Sub Form_Current()
Dim SumAmt As Currency
SumAmt = Me.mySubForm.Form![txtSumAmt].Value
If txtGTotal.Value <> SumAmt Then
MsgBox ("Amounts do not agree." & _
vbCr & "Sum of individual amounts is: " & SumAmt)
txtGTotal.SetFocus
End If
But thus only works when the user moves ON to the record, not OFF of it.
Plus, if there are many subform records, the value of SumAmt is reported as
zero when the onCurrent event initially fires so the message box is
displayed even when in fact the two totals are the same.
I think my whole approach to this may be flawed. Hopefully someone out
there who has worked with subtotaling subforms can give me some direction on
how to proceed.
Dave
PS I could just set txtGTotal on the main form equal to txtSumAmt on the
subform. However, both the total and the sub amounts are available for input
and we want a one to be a check on the other for data validation purposes .
amount textboxes (txtAmt) in the individual records on the subform should
sum up to the amount on the main form (txtGTotal). If they do not, I need
to alert the user before moving off the record.
I created a hidden text box (txtSumAmt) on the subform that sums the
individual txtAmt text boxes. I can compare this to txtGTotal on the main
form but I have two problems.
1. I don't know the event that triggers when the user moves off the current
record.
2. I tried coding the onCurrent event of the main form with this:
Private Sub Form_Current()
Dim SumAmt As Currency
SumAmt = Me.mySubForm.Form![txtSumAmt].Value
If txtGTotal.Value <> SumAmt Then
MsgBox ("Amounts do not agree." & _
vbCr & "Sum of individual amounts is: " & SumAmt)
txtGTotal.SetFocus
End If
But thus only works when the user moves ON to the record, not OFF of it.
Plus, if there are many subform records, the value of SumAmt is reported as
zero when the onCurrent event initially fires so the message box is
displayed even when in fact the two totals are the same.
I think my whole approach to this may be flawed. Hopefully someone out
there who has worked with subtotaling subforms can give me some direction on
how to proceed.
Dave
PS I could just set txtGTotal on the main form equal to txtSumAmt on the
subform. However, both the total and the sub amounts are available for input
and we want a one to be a check on the other for data validation purposes .