I have a subform in datasheet view for entering species count data; one record for species with several fields for different count techniques and times. There are two fields to hold the total count across columns for each record, one locked field for the calculated total for the row, the other for the user to optionally enter a modified total (rounded or whatever) if desired (This is needed). The following code shows how I update the Totals field when navigating to a new record.
Question 1. Does my approach to totalling counts seem sound?
Question 2. How can I get the total to update when tabbing from field to field in the subform, whithin the same record?
-----------------------------------------
Where would we be if we didn't try?
Question 1. Does my approach to totalling counts seem sound?
Question 2. How can I get the total to update when tabbing from field to field in the subform, whithin the same record?
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Screen.ActiveControl.ControlType = acTextBox Then
Call UpdateMyTotal
End If
End Sub
Private Sub UpdateMyTotal()
Dim iTotal
Dim ctl As Control
iTotal = 0
For Each ctl In Me.Controls
''If ctrl.Tag = 0 Then it is ignored in calculations.
If ctl.ControlType = acTextBox And ctl.Tag <> 0 Then
If Not Trim(ctl.Value & "") = "" And IsNumeric(ctl.Value) Then iTotal = iTotal + ctl.Value
Next ctl
'This line writes the new calculated total for this species to the table for this Site.
Me.txtTtl = iTotal
End Sub
-----------------------------------------
Where would we be if we didn't try?