Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2003
    Posts
    4

    Unanswered: Problems with summing textboxes...

    I have tried to add the contents of ten textboxes and place that sum into another textbox that is at the bottom of the column. as it loops through each textbox and reaches a textbox that is blank or empty, it kicks out an error. How can I check each textbox for a value and exclude the textboxes that are empty or Null?

    Here is where I am.

    Sub SumMoisture()

    Dim MoistureTotal
    Dim i As Integer

    Dim Item(14)
    Item(0) = Moisture1.Value
    Item(1) = Moisture2.Value
    Item(2) = Moisture3.Value
    Item(3) = Moisture4.Value
    Item(4) = Moisture5.Value
    Item(5) = Moisture6.Value
    Item(6) = Moisture7.Value
    Item(7) = Moisture8.Value
    Item(8) = Moisture9.Value
    Item(9) = Moisture10.Value
    Item(10) = Moisture11.Value
    Item(11) = Moisture12.Value
    Item(12) = Moisture13.Value
    Item(13) = Moisture14.Value
    Item(14) = Moisture15.Value

    For i = 0 To 14
    If Not IsNull(Item(i)) Then
    MoistureTotal = Item(i) + Item(i)
    End If
    Next i

    txtMoistureTotal.Value = MoistureTotal

    End Sub

    Any Help would be greatly appreciated.

  2. #2
    Join Date
    Jul 2004
    Posts
    64
    As long as you are using sum.. You could use the Nz command and have it return 0 if the field is null

  3. #3
    Join Date
    Aug 2003
    Location
    Cleveland USA
    Posts
    184

    Smile use Nz()

    You could use the Nz() function like this:

    Item(0) = Nz(Moisture1.Value)

    All null values will be converted to a zero, and the summation should work.

  4. #4
    Join Date
    Mar 2003
    Posts
    4
    Thanks. I appreciate your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •