this damned check box!

a.mlw.walker

Registered User.
Local time
Today, 13:53
Joined
Jun 20, 2007
Messages
36
Hi, I have a checkbox, and when its value is 1 (I understand this means its selected) I want a textbox, which is the control of a field called flag (and is invisible) on the form to take the value of F, and relay to the field on the table. but it doesnt relay to the table.
My code is under the onclick event procedure for the checkbox and is

Private Sub Check4_Click()
If Check4.Value = 1 Then
Me![Text7] = "F"
Else
End If
End Sub

Please help me
Thanks
Alex

P.S I have just made the source of the checkbox, the field in the table to ammend - flagged. My new code is
Private Sub Check4_Click()
If Check4.Value = 1 Then
[Flagged] = "F"
Else
End If
End Sub

But it adds a -1 if i do tick the check box, and a 0 if i dont...
 
Last edited:
No quite sure what you are trying to do, but you have the value wrong. When checked the value is -1 and when unchecked it is 0.
 
I want a field in a table to have an F in, when checked, and do nothing when unchecked
 
Thanks, yeah it the second function i wrote above now works, when you click it, but you cant unclick it, the image of the text box is sort of greyed out, when you click it the tick doesnt come or go, but it does put an F in the field. But if you click it again, you cant remove the tick, and therefore remove the F??
Thanks
Alex
 
The reason why your code is not working is as follows

your code is actually

Code:
If Check4.Value = 1 Then
     [Flagged] = "F"
Else
           [COLOR="Red"]  'NOTHING IN HERE!!![/COLOR]
End If
End Sub

so you are doing something if the value is 1, but you are not doing anything otherwise - hence the flag gets set to F, but not when you unset it

Now, prsonally i would not use numeric values to test a check box - a check box can only be true or false, so ignore the numeric equivalents access actually stores and just use the constants TRUE and FALSE. One reason for doing this is that if MS ever changed how they store true and false, your code will still work. I think its also more readable

secondly you don't need to use the value property

so instead use this code, which i think is more readable

Code:
If Check4 = TRUE Then   'although just  -- if check4 -- does the same thing
     [Flagged] = "F"
Else
     [COLOR="Red"][flagged]="Not F"   'turn it off[/COLOR]

End If
End Sub


now doing it this way, you are "pushing " the F and Not F values into the flagged text box with the after update event. Look at it the other way, from the point of view of the flagged textbox. In there you could instead use the control source of THAT textbox, to directly test the checkbox, and "pull" the value in automatically

ie the control source for the flagged text box will be this

Code:
=iif(check4,"F","Not F")

(note that you can just say if check4, it implies .... if check4 = true)

so in this case you don't need any code at all. Note that you can't use this if flagged is already bound to something.

its really a matter of taste as to which one is best, although your app may indicate a push or pull method is the better one. eg if you do it the second way, you can set the check box in code (which doesn't fire the update events), and still manage your flag correctly.

Note also that Using the first method, you also need to test the flag in the current event as well as the update events, to get the initial state of the check box.

Rambling a bit now, but I hope this helps.
 
Last edited:
Yeah that did help. It definately cleared up True false stuff. I was trying to work out why it weasnt true/false, but it still doesnt seem to work.
I have the control source of check box Flag, this is my code:
Code:
Private Sub Check43_AfterUpdate()
If Check43 = True Then
[Flag] = "F"
Else
[Flag] = ""
End If
End Sub
because i dont want anything in the flag field if unchecked, and the checkbox still is grey - cant put tick in it, and F doesnt appear in the field.
 
When an item is greyed out, that usually means someone has locked it or disabled it or something. Were you playing with other properties of the checkbox elsewhere on the form?
 
just chipping in on this - put a me.refersh after you code
 
also what is the default value on the tick box?? - there might not be one and this might throw a wobbley .
g
 

Users who are viewing this thread

Back
Top Bottom