I have a function that totals columns from a grid and displays the amounts in a textbox....it works great when there are records found but if the user clicks on the "total" button with no records i get the error "subscript out of range"...i want it to display "0".....i tried changing....For R = 0 To grid.Rows -1 to For R= 0 To -1..it displays a "0" when no records are found but it doesn't help......can anyone help......here is what i have....
Private Function TotalColumn(grid As MSFlexGrid, ByVal ColIndex As Long) As Long
Dim R As Long
Dim total As Long
For R = 0 To grid.Rows - 1
If IsNumeric(grid.TextMatrix(R, ColIndex)) Then
total = total + (grid.TextMatrix(R, ColIndex))
End If
Next R
TotalColumn = total
End Function
Private Function TotalColumn(grid As MSFlexGrid, ByVal ColIndex As Long) As Long
Dim R As Long
Dim total As Long
For R = 0 To grid.Rows - 1
If IsNumeric(grid.TextMatrix(R, ColIndex)) Then
total = total + (grid.TextMatrix(R, ColIndex))
End If
Next R
TotalColumn = total
End Function