Disable Checkbox

A

Amelia

I have an inventory form that I have a sold check box on. Once the check box
is marked that the item is sold, I want it to be disabled ( I also have an
embedded macro that runs when it is clicked to open the sold form to fill in
the buyer information). So I tried to run this code:

If Me![Sold] = yes Then
Me![Sold].Enabled = no
Else
Me![Sold].Enabled = yes
End If

In the After update event. It errors out saying it can't disable the control
while it has the focus. That makes sense. But then I am not sure where I
should put the code? Or if there is a better way to do this let me know! I
want to mark individual records, I don't want to disable it for all records.
 
A

Al Campagna

Amelia,
The error means... you can't disable this control, the focus (cursor)
is in that control right now.
Just move the Focus to another control before disabling
the checkbox.
You put the code in the AfterUpdate event of the checkbox...
(use your own object names)

Private Sub YourCheckBox_AfterUpdate()
SomeOtherFieldName.SetFocus
YourCheckBox.Enabled = YourCheckBox = False
End Sub

But... you also need the enabling part of that code on the OnCurrent
event of the form. If not, the first time the YourCheckBox gets disabled...
all YourCheckBoxes in the current recordset will be disabled. You need to
Enable/Disable the check when accessing each record.

Private Sub Form_Current()
YourCheckBox.Enabled = YourCheckBox = False
End Sub
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
T

Tom Wickerath

Hi Amelia,
In the After update event. It errors out saying it can't disable the control
while it has the focus. That makes sense. But then I am not sure where I
should put the code?

Have you tried Form_Current?


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________

Amelia said:
I have an inventory form that I have a sold check box on. Once the check box
is marked that the item is sold, I want it to be disabled ( I also have an
embedded macro that runs when it is clicked to open the sold form to fill in
the buyer information). So I tried to run this code:

If Me![Sold] = yes Then
Me![Sold].Enabled = no
Else
Me![Sold].Enabled = yes
End If

In the After update event. It errors out saying it can't disable the control
while it has the focus. That makes sense. But then I am not sure where I
should put the code? Or if there is a better way to do this let me know! I
want to mark individual records, I don't want to disable it for all records.
 
J

John W. Vinson

I have an inventory form that I have a sold check box on. Once the check box
is marked that the item is sold, I want it to be disabled ( I also have an
embedded macro that runs when it is clicked to open the sold form to fill in
the buyer information). So I tried to run this code:

If Me![Sold] = yes Then
Me![Sold].Enabled = no
Else
Me![Sold].Enabled = yes
End If

In the After update event. It errors out saying it can't disable the control
while it has the focus. That makes sense. But then I am not sure where I
should put the code? Or if there is a better way to do this let me know! I
want to mark individual records, I don't want to disable it for all records.

An alternate approach uses *no code at all*!

Select the checkbox in form design view. On the Menu select Format...
Conditional Formatting.

Choose True as the value, and select the "greyed out" option.
 
S

Stuart McCall

John W. Vinson said:
I have an inventory form that I have a sold check box on. Once the check
box
is marked that the item is sold, I want it to be disabled ( I also have an
embedded macro that runs when it is clicked to open the sold form to fill
in
the buyer information). So I tried to run this code:

If Me![Sold] = yes Then
Me![Sold].Enabled = no
Else
Me![Sold].Enabled = yes
End If

In the After update event. It errors out saying it can't disable the
control
while it has the focus. That makes sense. But then I am not sure where I
should put the code? Or if there is a better way to do this let me know! I
want to mark individual records, I don't want to disable it for all
records.

An alternate approach uses *no code at all*!

Select the checkbox in form design view. On the Menu select Format...
Conditional Formatting.

Choose True as the value, and select the "greyed out" option.

Nice trick John! I would never have thought of that.

If it were me, I'd put a comment in one of the checkbox's event procs to
remind me how it's being disabled. Months down the line and I'd most
definitely have forgotten.
 
T

tighe

John,

maybe i am missing something but Conditional Formatting is gray for me with
a checkbox is selected, please advise.
AC2007, XP.

thanks in advance.

John W. Vinson said:
I have an inventory form that I have a sold check box on. Once the check box
is marked that the item is sold, I want it to be disabled ( I also have an
embedded macro that runs when it is clicked to open the sold form to fill in
the buyer information). So I tried to run this code:

If Me![Sold] = yes Then
Me![Sold].Enabled = no
Else
Me![Sold].Enabled = yes
End If

In the After update event. It errors out saying it can't disable the control
while it has the focus. That makes sense. But then I am not sure where I
should put the code? Or if there is a better way to do this let me know! I
want to mark individual records, I don't want to disable it for all records.

An alternate approach uses *no code at all*!

Select the checkbox in form design view. On the Menu select Format...
Conditional Formatting.

Choose True as the value, and select the "greyed out" option.
 
J

John W. Vinson

John,

maybe i am missing something but Conditional Formatting is gray for me with
a checkbox is selected, please advise.

sorry, got it backwards: use False rather than True as the checkbox in order
to disable the control if the box is UNchecked.
 

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