QUESTION ABOUT DISABLING A BUTTON ON A FORM

A

Ayo

I have 2 checkbox on a form and a button. The button is disabled when the
form is loaded and enabled when either of the checkboxes is checked. What I
want to do is set things up such that when the checkboxes are both unchecked,
the button is disabled. I tried the On Current event of the form, see below,
but that didn't work.
Any ideas?
Thanks

Private Sub Form_Current()
If Me.chkFilterBy.Value = False And Me.chkTimeRange.Value = False Then
Me.cmdFilter.Enabled = True
Else
Me.cmdFilter.Enabled = False
End If
End Sub

Private Sub Form_Load()
Me.cmdFilter.Enabled = False
Me.txtTodaysDate = Now()
Me.tblConstructionLog_subform1.Form.RecordSource = "SELECT * FROM
tblConstructionLog WHERE FALSE"
End Sub
 
A

Ayo

I tried:
Private Sub Form_Current()
If ([chkFilterBy]) = -1 And ([chkTimeRange]) = -1 Then
Me.cmdFilter.Enabled = False
Else
Me.cmdFilter.Enabled = True
End If
End Sub
and it still doesn't work.

Wayne-I-M said:
If ([chkFilterBy]) = -1 And ([chkTimeRange]) = -1 Then


--
Wayne
Manchester, England.



Ayo said:
I have 2 checkbox on a form and a button. The button is disabled when the
form is loaded and enabled when either of the checkboxes is checked. What I
want to do is set things up such that when the checkboxes are both unchecked,
the button is disabled. I tried the On Current event of the form, see below,
but that didn't work.
Any ideas?
Thanks

Private Sub Form_Current()
If Me.chkFilterBy.Value = False And Me.chkTimeRange.Value = False Then
Me.cmdFilter.Enabled = True
Else
Me.cmdFilter.Enabled = False
End If
End Sub

Private Sub Form_Load()
Me.cmdFilter.Enabled = False
Me.txtTodaysDate = Now()
Me.tblConstructionLog_subform1.Form.RecordSource = "SELECT * FROM
tblConstructionLog WHERE FALSE"
End Sub
 
G

George Nicholson

Switch Me.cmdFilter.Enabled = True with its opposite.

Based on what you say you want, I think you simply have them reversed.

Keep in mind that Form_Current will fire after Form_Load, so disabling in
Form_Load no longer has any real effect.
 
G

George Nicholson

Another approach:

Select Case Abs(nz(Me.chkFilterBy,0)) + Abs(nz(Me.chkTimeRange,0))
Case 0
'Neither Checked
Me.cmdFilter.Enabled = False
Case 1
' 1 checked
Me.cmdFilter.Enabled = True
Case 2
' Both checked
Me.cmdFilter.Enabled = True
End Select

(Note: "Case 1" and "Case 2" could be written as a single "Case 1, 2" if you
really want the same thing to happen, but i'm not entirely sure that you
do.)

This is overkill, but it has the advantage of being super easy to see what
its doing and modify/expand the logic.

If this doesn't do what you want, please provide a bit more detail than the
generally useless statement "it doesn't work".
 
A

Ayo

I tried all the different combinations and I still can't get the button to
disable when both checkboxes are unchecked.
 
A

Ayo

What I have are 2 checkbox on a form and 1 command button. The button is set
to disabled when the form is loaded and enabled when either of the checkboxes
is checked.
What I want to do with the button is have is enabled when either of the
checkbox is unchecked, and disabled when neither of the checkbox is checked.
This is all I am trying to do and I can't figure out why it is not working.
 
W

Wayne-I-M

Well I'm lost then - we have given you a couple of samples that "should" work.

It seems quite a simple thing.

I take it you have 2 tick boxes

chkTimeRange
and
chkFilterBy

If either of these is checked (=-1) then you want a button to be enabled.
If neither are ticked you want the button not enabled. And you want the same
criteria on current

______________________
This works - I just tested it. (change the button name to what it is)


Private Sub chkFilterBy_AfterUpdate()
If Me.chkFilterBy = -1 Or Me.chkTimeRange = -1 Then
Me.ButtonName.Enabled = True
Else
Me.ButtonName.Enabled = False
End If
End Sub


Private Sub chkTimeRange_AfterUpdate()
If Me.chkFilterBy = -1 Or Me.chkTimeRange = -1 Then
Me.ButtonName.Enabled = True
Else
Me.ButtonName.Enabled = False
End If
End Sub

Private Sub Form_Current()
If Me.chkFilterBy = -1 Or Me.chkTimeRange = -1 Then
Me.ButtonName.Enabled = True
Else
Me.ButtonName.Enabled = False
End If
End Sub
 
G

George Nicholson

Make sure the button does not have the focus when you try to disable it. Be
sure its Default property is No.

Make sure the Disabling code is in the AfterUpdate event of both checkboxes
and the Current event.

In Form Design, make sure the Form.OnCurrent, chkFilterBy.OnAfterUpdate and
chkTimeRange.OnAfterUpdate ALL have their properties set to [EventProcedure]
and that clicking the ellipsi (...) leads you to the code you have written.
 

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