George Too
Registered User.
- Local time
- Today, 12:37
- Joined
- Aug 12, 2002
- Messages
- 198
Hi all,
I was wondering how to reduce the following code:
'***********************
'Initialize variables
N = 0 'Number of rolls
A = 0 'Sum of All entries
'Add fields
If Not IsNull([subfrmRepeats].[Form]![Roll1]) And [subfrmRepeats].[Form]![Roll1] <> 0 Then
A = A + [subfrmRepeats].[Form]![Roll1]
N = N + 1
End If
If Not IsNull([subfrmRepeats].[Form]![Roll2]) And [subfrmRepeats].[Form]![Roll2] <> 0 Then
A = A + [subfrmRepeats].[Form]![Roll2]
N = N + 1
End If
If Not IsNull([subfrmRepeats].[Form]![Roll3]) And [subfrmRepeats].[Form]![Roll3] <> 0 Then
A = A + [subfrmRepeats].[Form]![Roll3]
N = N + 1
End If
'***********************
I have 30 of these [RollN] controls in the subform "subfrmRepeats".
Now, I have seen somewhere that I can use something like this:
For Each ctl In subfrmRepeats.Controls
but I don't know what else follows.
Thank you.
I was wondering how to reduce the following code:
'***********************
'Initialize variables
N = 0 'Number of rolls
A = 0 'Sum of All entries
'Add fields
If Not IsNull([subfrmRepeats].[Form]![Roll1]) And [subfrmRepeats].[Form]![Roll1] <> 0 Then
A = A + [subfrmRepeats].[Form]![Roll1]
N = N + 1
End If
If Not IsNull([subfrmRepeats].[Form]![Roll2]) And [subfrmRepeats].[Form]![Roll2] <> 0 Then
A = A + [subfrmRepeats].[Form]![Roll2]
N = N + 1
End If
If Not IsNull([subfrmRepeats].[Form]![Roll3]) And [subfrmRepeats].[Form]![Roll3] <> 0 Then
A = A + [subfrmRepeats].[Form]![Roll3]
N = N + 1
End If
'***********************
I have 30 of these [RollN] controls in the subform "subfrmRepeats".
Now, I have seen somewhere that I can use something like this:
For Each ctl In subfrmRepeats.Controls
but I don't know what else follows.
Thank you.