Count text boxes

A

AHopper

In the On Open event of a form I use the following to
calculate the maximum and minimum number required to do a
job.
With Me
MaxRequired = ((Fix(Nz(.MasterUnits) / 9)) + 1) * Nz
(.JobQty)
MinRequired = (Fix(Nz(.MasterUnits) / 9)) * Nz(.JobQty)
End With
On the same form I have nine text boxes (TSA1 through TSA9)
that I would like to count the following:
1)how many are equal to or greater than the minrequired
2) how many are equal to or greater than the maximum
required.
3)how many are greater than the minimum required.

Using the following I can count the number of low numbers,
high numbers and the number over the low number.

Dim dblLowestTA As Double
Dim dblHighestTA As Double
Dim dblValueTA As Double
Dim CountMin As Integer
Dim CountMax As Integer
CountMin = 0
CountMax = 0
CountOverMin = 0
For intControl = 1 To 9
dblValueTA = Me.Controls("TSA" & intControl).Value
If dblValueTA = dblLowestTA Then CountMin =
CountMin + 1
If dblValueTA = dblHighestTA Then CountMax =
CountMax + 1
If dblValueTA > dblLowestTA Then CountOverMin =
CountOverMin + 1

I made the following modification to count text boxes
equal to or greater than MinRequired and equal to or
greater than MaxRequired but so far I have had no success.

Dim dblLowestTA As Double
Dim dblHighestTA As Double
Dim dblValueTA As Double
Dim CountMin As Integer
Dim CountMax As Integer
CountMin = 0
CountMax = 0
CountOverMin = 0
For intControl = 1 To 9
dblValueTA = Me.Controls("TSA" & intControl).Value
If (dblValueTA >= MinRequired) = dblLowestTA Then
CountMin = CountMin + 1
If (dblValueTA >= MaxRequired) = dblHighestTA Then
CountMax = CountMax + 1
If dblValueTA > dblLowestTA Then CountOverMin =
CountOverMin + 1

Thank you in advance for your help.

Allan
 
R

Rob Oldfield

I don't really follow exactly what you're trying to do, and having 9 text
boxes with values related to the main record by a one to one suggests that
your design is a bit out (should really be a sub table I think) but....

If (dblValueTA >= MinRequired) = dblLowestTA Then

....the first part (dblValueTA>= MinRequired) will return either true or
false. And you're comparing that to a double value. Your logic isn't quite
right.

And taking another look before hitting my 'Send' button, you're dimming
dblLowestTA, but you're not actually setting it to a value anywhere.
 
A

AHopper

Rob, sorry that it took me so long to respond (off for
Easter) and I am also sorry that my description was not
clear. However, even though you did not understand what I
was trying to to, you pointed me in the right direction
and it works. The key lay in the fact that I was comparing
to a double value. I really only needed to use the
MinRequired and MaxRequired.
Thank you very much for your response. I looked at that
several times and couldn't see what was wrong. Now it is
so obvious.

Thanks again
Allan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top