Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clear Check Box or Yes/No Fields

Status
Not open for further replies.

tpearo

Technical User
Apr 24, 2000
124
US
Is there a way to clear any yes/no or checkboxes with a button or something so that anything that is checked as Yes gets cleared to NO.

I have a list of employees to schedule work. I have a check box checked if they are suppose to work the box is set to checked yes but I want to be able to automatically clear the boxes checked yes by clicking a button or a reset.
 
This will do what you need provided the controls are all on the same form. I have used this where chkSelectAll is a checkbox on the same form. In this example I made sure not to reset the "chkSelectAll" check box and used the "Tag" property (set to "*") of other check boxes that did not apply. You can remove that if not needed


'---
Private Sub chkSelectAll_Click()

Dim x as integer, num as integer
Dim data as object
set data = Me.Form
num = data.Count
For x = 1 To num - 1
If data(x - 1).ControlType = acCheckBox And data(x - 1).Name <> "chkSelectAll" And data(x - 1).Tag <> "*" Then
data(x - 1).value = Me.chkSelectAll.value
End If
Next x

End sub
 
You can filter out certain controls while looping, but the basic technique is this:
Code:
Private Sub cmdClearAll_Click()
  Dim ctl As Control
  
  For Each ctl In Me.Controls
    If TypeOf ctl Is CheckBox Then
      If ctl.Value = True Then
        ctl.Value = False
      End If
    End If
  Next ctl
End Sub

VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
Assuming your form is based on tblSchedule with the fields EmpName, OnDuty.

CurrentDB.Execute "UPDATE tblSchedule Set OnDuty = 0"
Me.Requery

If your working with a filtered data set, then just include the WHERE statement.
 
hi, I saw this post, and was hoping someone could help. I have a lot of checkboxs , on 2 frames on 2 tab pages.

I have code that is not working. When I put this into the clear button code :

Code:
Dim ctl As Control
  
  For Each ctl In Me.Controls
    If TypeOf ctl Is CheckBox Then
      If ctl.Value = True Then
        ctl.Value = False
      End If
    End If
  Next ctl

It says that I entered an expression that has no value. huh?

Here is the code that I was using. It makes the appropriate checkboxes invisible, 1/2 the reset, but when they are compelled to become visible again, they are all checked.

I dont understand why all checked.

Code:
Me.ChkDActType.Visible = False
Me.ChkDActDate.Visible = False
Me.ChkDAppSource.Visible = False
Me.ChkDCandType.Visible = False
Me.ChkDCand.Visible = False
Me.ChkDGroup.Visible = False
Me.ChkDJobTitle.Visible = False
Me.ChkDOffice.Visible = False
Me.ChkDHired.Visible = False
Me.FrmDetGroup.Visible = False
Me.ChkDActType.Value = False
Me.ChkDActDate.Value = False
Me.ChkDAppSource.Value = False
Me.ChkDCandType.Value = False
Me.ChkDCand.Value = False
Me.ChkDGroup.Value = False
Me.ChkDJobTitle.Value = False
Me.ChkDOffice.Value = False
Me.ChkDHired.Value = False
Me.ChkActivity.Visible = False
Me.ChkAppDate.Visible = False
Me.ChkAppSource.Visible = False
Me.ChkCandType.Visible = False
Me.ChkDeptGroup.Visible = False
Me.ChkJobTitle.Visible = False
Me.ChkOffice.Visible = False
Me.ChkStartDate.Visible = False
Me.FrmStatGroup.Visible = False
Me.ChkActivity.Value = False
Me.ChkAppDate.Value = False
Me.ChkAppSource.Value = False
Me.ChkCandType.Value = False
Me.ChkDeptGroup.Value = False
Me.ChkJobTitle.Value = False
Me.ChkOffice.Value = False
Me.ChkStartDate.Value = False


whereever it has a check.value I have also tried optionvalue and that is brining the same result. They all end up checked not unchecked.

[sadeyes]

please help.



misscrf

It is never too late to become what you could have been ~ George Eliot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top