Uncheck a check box (1 Viewer)

velcrowe

Registered User.
Local time
Yesterday, 23:07
Joined
Apr 26, 2006
Messages
86
I don't know how difficult this is but, I would like to uncheck a check box when I don't want that value filtered on my form. I know all the check boxes are cleared when the form is closed. I just want to select the value of the check box and if I don't want it, uncheck it. Thank you:rolleyes:
 

Alc

Registered User.
Local time
Yesterday, 23:07
Joined
Mar 23, 2007
Messages
2,407
[Forms]![name of check box] = False

sets it to un-ticked

[Forms]![name of check box] = True

sets it to ticked
 

velcrowe

Registered User.
Local time
Yesterday, 23:07
Joined
Apr 26, 2006
Messages
86
Where would I place this code? Would I create an event procedure for the check box or would it go on the form? I have three check boxes on the form so I may need to select two out of three, and so on
 

Alc

Registered User.
Local time
Yesterday, 23:07
Joined
Mar 23, 2007
Messages
2,407
Yes, you create an event for the box, on the form.
Let's say, for example, that ticking box 1 automatically means that boxes 2 and 3 should be cleared. In the code behind the 'AfterUpdate' event of box 1, you'd add
Code:
If [Forms]![[I]name of check box1[/I]] = True then
       [Forms]![[I]name of check box2[/I]] = False
       [Forms]![[I]name of check box3[/I]] = False
End if
 

velcrowe

Registered User.
Local time
Yesterday, 23:07
Joined
Apr 26, 2006
Messages
86
How would I then clear a box that's selected without using an event from the other check boxes? For instance, I select box 1, change my mind and need to clear the check from box 1...without clicking on box 2 or 3. Almost like turning on a switch and then turning it off. I ask because I need to setup box 2 and 3 the same way. I ultimately need to run reports say with box 1 and 3 checked or 2 and 3 check, etc. Thank you
 

Alc

Registered User.
Local time
Yesterday, 23:07
Joined
Mar 23, 2007
Messages
2,407
You could manually click on box 1. That would uncheck it and, because there's no mention of what to do if it's false in the code, not affect boxes 2 or 3.

If you mean how could you set it to false without clicking on it or on the other boxes, you'd need an event somewhere that would do it, whether that's behind a different item on the form, or behind one of the form's own events.
 

velcrowe

Registered User.
Local time
Yesterday, 23:07
Joined
Apr 26, 2006
Messages
86
If I check the box so that the value = 2007, like this me.checkbox.value = 2007, what code would I use to click on the box again and remove the value. If me.checkbox.value = 2007 then me.checkbox.value = null does not work. Any help is greatly appreciated. :eek:
 

Alc

Registered User.
Local time
Yesterday, 23:07
Joined
Mar 23, 2007
Messages
2,407
If it's a checkbox, as opposed to a text field, I'm not sure you can set it to anything other than true or false?

To clear it, try
Me.CheckBox = False
 

velcrowe

Registered User.
Local time
Yesterday, 23:07
Joined
Apr 26, 2006
Messages
86
Thank you so much for all your help. As I click the box it sets the value to 2007 so that I can run filter the results for my report. That works fine. I just don't know how to say that if it's check or the field has a value then set the value to null or clear the check. If I make the default value of the check box 2007 in the field properties, the form opens with the box checked already.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 04:07
Joined
Sep 12, 2006
Messages
15,696
in order to not see checked items, yuo either need to filter the items, or to have the query supporting the form, to take the checked setting into account

BUT after you clik it, it wont automatically remove itslef form the displayed items, until you requery the from

try puuting an option group at the top of the from

three options
1 - checked items
2. - unchecked items
3 - all items

and in the after update event for the option group play around with filter settings. you probably need another button though, to do a me.requery (or add it the checkboxes afterupdate event.

you see what i mean though - the form shows a snapshot until you explicitly requery it
 

Alc

Registered User.
Local time
Yesterday, 23:07
Joined
Mar 23, 2007
Messages
2,407
No problem, I hope I'm able to help a bit. The more experienced posters here were/are a big help for me.

I think the fact that you're setting a check box to a value other than True or False is confusing me a bit.

An unticked box will have a value of False.
A ticked box will have a value of True.
Setting the value to '2007' appears to be interpreted by the box as True.

If I were you, I'd declare some variable and set that to 2007 (or whatever else), based on whether the box is checked or not. For example, if there's a button you click to run the report, the OnClick event could use something like
Code:
Dim str_Year as String
 
If Me.CheckBox2006 = True Then
    str_Year = "2006"
If Me.CheckBox2007 = True Then
    str_Year = "2007"
If Me.CheckBox2008 = True Then
    str_Year = "2008"
End If
 
[I]{Code to open report using str_Year as the filter}[/I]
 

velcrowe

Registered User.
Local time
Yesterday, 23:07
Joined
Apr 26, 2006
Messages
86
I combined some of all your post to come up with this answer:

In the onclick event of my command button for the report I typed

If me.checkbox = true then me.checkbox.value = 2007 and so on for each box. There's only five and it's working great. I get the value and the check and clear check functionality.
 

Users who are viewing this thread

Top Bottom