S
Steve
Greetings:
I would like to calculate the sum of 4 text fields (txtFld1, txtFld2,
txtFld3, txtFld4) when the user clicks cmdCalc. Prior to performing the
calculation, I would like to make sure that no null values exist in any of
these text fields. Is there a more efficient way of determining this without
individually assessing each field as I've done below? Thanks for any
assistance. Steve
Private Sub cmdCalc_Click()
On Error GoTo Err_cmdCalc_Click
'define variables
Dim intScore1 As Integer
Dim intScore2 As Integer
Dim intScore3 As Integer
Dim intScore4 As Integer
Dim intTotal As Integer
'make sure each of the 4 fields have a value
If Not IsNull(Me.txtFld1) Then
intScore1 = Me.txtFld1
Else
Exit Sub
End if
If Not IsNull(Me.txtFld2) Then
intScore2 = Me.txtFld2
Else
Exit Sub
End if
If Not IsNull(Me.txtFld3) Then
intScore3 = Me.txtFld3
Else
Exit Sub
End if
If Not IsNull(Me.txtFld4) Then
intScore4 = Me.txtFld4
Else
Exit Sub
End if
'add scores
intTotal = intScore1 + intScore2 + intScore3 + intScore4
'put the total into text field
Me.txtTotalScore = intTotal
Exit_cmdCalc_Click:
Exit Sub
Err_cmdCalc_Click:
MsgBox Err.Description
Resume Exit_cmdCalc_Click
End Sub
I would like to calculate the sum of 4 text fields (txtFld1, txtFld2,
txtFld3, txtFld4) when the user clicks cmdCalc. Prior to performing the
calculation, I would like to make sure that no null values exist in any of
these text fields. Is there a more efficient way of determining this without
individually assessing each field as I've done below? Thanks for any
assistance. Steve
Private Sub cmdCalc_Click()
On Error GoTo Err_cmdCalc_Click
'define variables
Dim intScore1 As Integer
Dim intScore2 As Integer
Dim intScore3 As Integer
Dim intScore4 As Integer
Dim intTotal As Integer
'make sure each of the 4 fields have a value
If Not IsNull(Me.txtFld1) Then
intScore1 = Me.txtFld1
Else
Exit Sub
End if
If Not IsNull(Me.txtFld2) Then
intScore2 = Me.txtFld2
Else
Exit Sub
End if
If Not IsNull(Me.txtFld3) Then
intScore3 = Me.txtFld3
Else
Exit Sub
End if
If Not IsNull(Me.txtFld4) Then
intScore4 = Me.txtFld4
Else
Exit Sub
End if
'add scores
intTotal = intScore1 + intScore2 + intScore3 + intScore4
'put the total into text field
Me.txtTotalScore = intTotal
Exit_cmdCalc_Click:
Exit Sub
Err_cmdCalc_Click:
MsgBox Err.Description
Resume Exit_cmdCalc_Click
End Sub