Minimum Values

ddrew

seasoned user
Local time
Today, 02:20
Joined
Jan 26, 2003
Messages
911
I have a counter on my form which will increase or decrease depending on weather a number of tick boxes report true or false. Is it possible to set a minimum aloud value on a box regardless of other criteria. At present I can depending on certail criteria, finish up with a - number which for other reasons, I dont want.
 
Out of interest, what do all the tickboxes represent? Is this a direct interpretation from a number of fields containing checkboxes?
 
Yes it is, Ok I have 5 check boxes, call them 1, 2, 3, 4, 5 for now.

Tick box 1 is a short cut to automatically tick the other four, this is just to save the user time.

If I tick No 1 the count goes to 4. If I then uncheck No 3 the count goes to 3. Thats fine. The problem occurs when I then uncheck No 1, doing this causes the count to go to -1. I'm trying to avoid this. My code reads like this:

x = Me.Total

If Me.Check1 = True Then
Let x = x + 4
Let Me.Total = x
Me.Check2 = True
Me.Check3 = True
Me.Check4 = True
Me.Check5 = True
End If
If Me.Check1 = FalseThen
Let x = x - 4
Let Me.Total = x
Me.Check2 = False
Me.Check3 = False
Me.Check4 = False
Me.Check5 = False

This for Check1

For the others it reads:


Dim x As Integer
x = Me.Total
If Me.Check2 = True Then
Let x = x + 1
Let Me.Total = x


If Me.Check2 = False Then
Let x = x - 1
Let Me.Total = x
End If

It all works fine except this minus number business!
 
Could you not use -

x=x-x for the Me!Check1 box, then it would subtract itself and always end up with zero?

Dave Eyley
 
Since True is equal to -1 and False is equal to 0, you can just add up the checkboxes and use the Abs function to return a postitive.

i.e.

Code:
Abs(Me.chk1 + Me.chk2 + Me.chk3 + Me.chk4)
 
Never used an Abs function. Where in the code would I put it?
 
Ive tried various combinations of this in my, but am unable to make it work correctly! Any help please!
 
Cracked it! Thanks for all the help. I thought I neded to leave in the Dim statements etc :o
 
Futhur question to this, as it stands it works fine. What about if I require one of the cheque boxes to represent more than 1 , 3 for arguements sake?
 
Put a value in the Checkbox's Tag property and then use Me.chk1.Tag
 
OK I did that but now it adds it evan if the check box reads false!
 
I set the tag to 4 but now whaen I do a total it adds 4 regardless as to wether it is true or false. I need it to only be + 4 when it reads true and subtract 4 when it is false.
 
Code:
Dim bytTotal As Byte
byt = IIf(Me.chk1,Me.chk1.Tag,0) + IIf(Me.chk2,Me.chk2.Tag,0) + _
     IIf(Me.chk3,Me.chk3.Tag,0) + IIf(Me.chk4,Me.chk4.Tag,0)
 
OK, Thanks for that. Having never done this before could you explain it to me. i.e the statement. So that I know for next time. In the meantime Im going to apply your suggestion. Thanks!
 
Ok, this is what I have but its not working at present. Check1 is the only Check Box that I want to represent 4. All other check Boxes represent 1 So what I'm trying to say is

Check1 = 4
Check2 = 1
Check3 = 1
Check4 = 1
Check5 = 1

Total = 8

This applys only if a check box is true if its false then it represents 0
I'm geting a little lost with this!

Dim bytTotal As Byte
byt = IIf(Me.Check1, Me.Check1.Tag, 0)

If Me.Check1 = True Then
Me.Total = Abs(Me.Check1 + Me.Check2 + Me.Spartan3 + Me..Check4 + Me.Me.Check5)

End If
If Me.Check1 = False Then
Me.Total = Abs(Me.Check1 + Me.Check2 + Me.Spartan3 + Me.Check4 + Me.Me.Check5)
End If
 
I posted this and got lots of posotive help with this problem yesterday. But I need a little more just to square this final piece away. Thanks!

Ok, this is what I have but its not working at present. Check1 is the only Check Box that I want to represent 4. All other check Boxes represent 1 So what I'm trying to say is

Check1 = 4
Check2 = 1
Check3 = 1
Check4 = 1
Check5 = 1

Total = 8

This applys only if a check box is true if its false then it represents 0
I'm geting a little lost with this!

Dim bytTotal As Byte
byt = IIf(Me.Check1, Me.Check1.Tag, 0)

If Me.Check1 = True Then
Me.Total = Abs(Me.Check1 + Me.Check2 + Me.Spartan3 + Me..Check4 + Me.Me.Check5)

End If
If Me.Check1 = False Then
Me.Total = Abs(Me.Check1 + Me.Check2 + Me.Spartan3 + Me.Check4 + Me.Me.Check5)
End If
 
You are making it far too complicated. The line I posted above with the IIf() statements should be all you need. The IIf() is checking if each checkbox is true or false and adding the relevant value (either the .Tag or 0). You don't need the Abs function anymore either.
 
Ha! Now I understand. Sorry to have been a pain. You've been a great help. Thanks for your time! :)
 

Users who are viewing this thread

Back
Top Bottom