Need help with code

A

Ayo

I have a problem and I hope someone can help with it. I have a form with a
bunch of Checkboxes. And I have 3 Option buttons: Select All, Make Selection
and Clear All, and 2 buttons. The buttons are disabled. Slect All checks all
the CheckBoxes and enable the buttons, Clear All uncheck all the CheckBoxes
and disable the buttons.
Make Selection is surposed to uncheck all the CheckBoxes with the buttons
still disabled. What I want to do next is this, any time a checkbox is
checked I want the 2 buttons to become enabled and if no checkbox is checked
I want the 2 buttons to be disabled.
I have tried the codes below, the Sub frmSelectMilestones_Click() works
fine but I still can't figire out how to enable the 2 buttons when at least
one checkbox is checked.
Any help will be greatly appreciated. Thanks.

Private Sub Form_Current()
Dim ctrl As Control, counter As Integer
Dim frm As Form
Set frm = Me.Form
counter = 0
For Each ctrl In frm.Controls
With ctrl
Select Case .ControlType
Case acCheckBox
If .Value = True Then
counter = counter + 1
End If
End Select
End With
Next ctrl
If counter >= 1 Then
Me.cmdRunAQuery.Enabled = True
Me.cmdRunOQuery.Enabled = True
ElseIf counter = 0 Then
Me.cmdRunAQuery.Enabled = False
Me.cmdRunOQuery.Enabled = False
End If
End Sub

Private Sub frmSelectMilestones_Click()
Dim counter As Integer
Dim ctrl As Control
Dim frm As Form
Set frm = Me.Form
counter = 0
Select Case frmSelectMilestones
Case 1
For Each ctrl In frm.Controls
With ctrl
Select Case .ControlType
Case acCheckBox
.Enabled = True
.Value = True
End Select
End With
Next ctrl
Me.cmdRunAQuery.Enabled = True
Me.cmdRunOQuery.Enabled = True
Case 2
For Each ctrl In frm.Controls
With ctrl
Select Case .ControlType
Case acCheckBox
.Enabled = True
.Value = False
End Select
End With
Next ctrl
Case 3
For Each ctrl In frm.Controls
With ctrl
Select Case .ControlType
Case acCheckBox
.Value = False
'.Enabled = False
End Select
End With
Next ctrl
Me.cmdRunAQuery.Enabled = False
Me.cmdRunOQuery.Enabled = False
End Select

End Sub
 
T

Tom Wickerath

Hi Ayo,

Try changing your Form_Current() procedure to a new function, perhaps named
something like EnableDisableCmdButtons. In the property sheet, set the
following properties:

Form
On Current........... =EnableDisableCmdButtons()

To each checkbox
After Update........ =EnableDisableCmdButtons()

You can use the lasso technique to select all checkboxes at once, as long as
you do not select any associated labels, or hold down the Shift key as you
select each checkbox individually. You might also want to set a default value
of 0 for each check box, so that it does not have the "greyed out" appearance
for a null state.

Note: If you use Themed Controls setting, you will not see this greyed out
appearance.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
A

Ayo

Thanks Tom. That worked great.

Tom Wickerath said:
Hi Ayo,

Try changing your Form_Current() procedure to a new function, perhaps named
something like EnableDisableCmdButtons. In the property sheet, set the
following properties:

Form
On Current........... =EnableDisableCmdButtons()

To each checkbox
After Update........ =EnableDisableCmdButtons()

You can use the lasso technique to select all checkboxes at once, as long as
you do not select any associated labels, or hold down the Shift key as you
select each checkbox individually. You might also want to set a default value
of 0 for each check box, so that it does not have the "greyed out" appearance
for a null state.

Note: If you use Themed Controls setting, you will not see this greyed out
appearance.


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top