PDA

View Full Version : Solved: Clear Checkboxes



jmentor
05-18-2006, 03:38 AM
I haved a form that contains a subform (datasheet)
that in turn has a yes/no tick box.
I would like to have all these checkboxes unticked
when the main form opens. Is there a way of
achieving this say as a OnOpen event or similar ?

Thanks for any help

OBP
05-18-2006, 11:27 AM
The best form event to use for this is the "On Current" event procedure.
Check boxes have to be set using their "value" not "yes/no" or "true/false" but -1 and 0. Set them to 0 to clear them.

Cosmos75
05-20-2006, 08:22 PM
I would create a procedure to uncheck all checkboxs and call if from the appropriate form event. The reason I would create a seperate procedure is so that I can call it from a command button or any other code behind the same form.

The following code will uncheck ALL checkboxes on a form but not it's subform. Keep in mind that this code works on a Checkbox control, NOT a Yes/No field displayed as a checkbox in datasheet view.

Private Sub Form_Current(Cancel As Integer)
UncheckALL
End Sub

Private Sub UncheckALL()
Dim ctrl As Control
For Each ctrl In Me.Controls
If ctrl.ControlType = acCheckBox Then ctrl = False
Next ctrl
End Sub
But you say the checkboxes are in your subform? In that is the case you will have to use the code in the subform or adapt it to look at controls in your subform.

Are the checkboxes bound to a field in a table? Not knowing much about what date you are displaying and how your data is related, I am wondering what you are trying to accomplish.

If the checkboxes are just Yes/No fields (that are being displayed as checkboxes in datasheet view) are you just wanting to set the value of a field for all show records in your subform to FALSE? If so, you could execute some SQL to set the value of that field for all displayed records (which you would have to figure out how to select only those being displyed) to false.

What exactly are you trying to accomplish and why? It would help to understand what data you are working with and what you are trying to fo with it.

Hope that helps!
:)

jmentor
05-21-2006, 05:53 AM
Cosmos75

Thanks for your help. It all worked well using that
method.

J