Clear all check boxes (1 Viewer)

Wayne Cramer

Registered User.
Local time
Today, 09:50
Joined
Aug 10, 2007
Messages
93
I have a form with a check box that controls a report which sends faxes to appropriate recipients. When the form closes I would like all check boxes to clear so the next time it is opened I can select recipients. Currently I have to deselect each check box one by one. A control button which would clear all check boxes would be a good solution also.
 

CraigDolphin

GrumpyOldMan in Training
Local time
Today, 07:50
Joined
Dec 21, 2005
Messages
1,583
Are the checkboxes bound to any fields or are they unbound?

If they are unbound, then change the default value to 0 (i.e., false).

If they are bound to a field, then you could create an update query that runs from vba code in the on_close event of the form and changes all the -1 (true) values in the form's record source to 0. You could use a similar approach in a command button also but, if you always want to do this when the form opens, you'd be better to use the on_close event of the form (or the on_current event instead if you want it to reset when you navigate off the record).
 

Luddite Lad

Registered User.
Local time
Tomorrow, 01:50
Joined
Aug 23, 2005
Messages
177
Easy just put the following code behind your form's on close event or on a button's on click event;

Me.Check1 = False
Me.Check2 = False
'Etc.
 

boblarson

Smeghead
Local time
Today, 07:50
Joined
Jan 12, 2001
Messages
32,059
This will clear all checkboxes on a form.

Code:
    Dim ctl As Control
    For Each ctl In Me.Controls
        If ctl.ControlType = acCheckBox Then
            ctl.Value = False
        End If
    Next ctl
 

CEH

Curtis
Local time
Today, 09:50
Joined
Oct 22, 2004
Messages
1,187
To add to Bobs post... in case you might have other check boxes on the form you do not want to change by the event, you could "Tag" the ones you DO want to clear.....

Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acCheckBox Then
If ctl.tag = "*" then
ctl.Value = False
End If
End if
Next ctl
 

BadScript

Registered User.
Local time
Today, 07:50
Joined
Oct 30, 2007
Messages
73
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acCheckBox Then
ctl.Value = False
End If
Next ctl
Many thanks, Excellent..
Is this possible for other controls as well? like clear all combo's and clear all textboxes or clear a whole form?
I have many controls in my unbound form and all I want is to clear my form with a button
 
Last edited:

KenHigg

Registered User
Local time
Today, 10:50
Joined
Jun 9, 2004
Messages
13,327
Here's a stab:

Dim ctl As Control
For Each ctl In Me.Controls
ctl.Value = False
Next ctl

???
ken
 

boblarson

Smeghead
Local time
Today, 07:50
Joined
Jan 12, 2001
Messages
32,059
Many thanks, Excellent..
Is this possible for other controls as well? like clear all combo's and clear all textboxes or clear a whole form?
I have many controls in my unbound form and all I want is to clear my form with a button
Code:
Dim ctl As Control
   For Each ctl In Me.Controls
      Select Case ctl.ControlType
         Case acCheckBox
            ctl.Value = False
         Case acComboBox
            ctl.Value = Null
         Case acTextBox
            ctl.Value = ""
      End Select
Next ctl
 

rainman89

I cant find the any key..
Local time
Today, 10:50
Joined
Feb 12, 2007
Messages
3,016
this thread is perfect. i said to myself this morning.. self.. wouldnt it be great if you had a select all option adn clear all option for the checkboxes?

and vualah?(sp i think its french or something) i found this thread.
 

boblarson

Smeghead
Local time
Today, 07:50
Joined
Jan 12, 2001
Messages
32,059
this thread is perfect. i said to myself this morning.. self.. wouldnt it be great if you had a select all option adn clear all option for the checkboxes?

and vualah?(sp i think its french or something) i found this thread.

Voila :D ...
 

BadScript

Registered User.
Local time
Today, 07:50
Joined
Oct 30, 2007
Messages
73
Code:
Dim ctl As Control
   For Each ctl In Me.Controls
      Select Case ctl.ControlType
         Case acCheckBox
            ctl.Value = False
         Case acComboBox
            ctl.Value = Null
         Case acTextBox
            ctl.Value = ""
      End Select
Next ctl
Thanks, it all works except for the clear textboxes.. I get a debug error..
 

boblarson

Smeghead
Local time
Today, 07:50
Joined
Jan 12, 2001
Messages
32,059
Sounds like you have a text box which can't be updated. In that instance it may make more sense for you to use the tag property to identify those text boxes on the form that need to be cleared and then use:

Code:
...
        Case acTextBox
           If ctl.Tag = "WhateverYouPutInTheTag" Then
               ctl.Value = ""
           End If
    End Select
 

BadScript

Registered User.
Local time
Today, 07:50
Joined
Oct 30, 2007
Messages
73
Must be the way i have my cascading combo's configured, can't get it done on access 2007.. I'll try the combo method explained in another threat this week..
In my 3rd combo i run a query that depends on the choice in the first combo and the 2nd combo ánd the result of this selection displayed in a textbox... I understand this is not the correct way but it runs in access 2003, gives probs in 2007..
 
Last edited:

Users who are viewing this thread

Top Bottom