check box that disables itself and other controls after use

G

Guest

I've read several of the posts with the similar subject of disabling controls
based off of a checkbox value, however I can't seem to get this to work.

I want a "one time use checkbox", meaning when a user clicks it, not only do
other controls become disabled, so does the checkbox itself (after update).
The thought behind this is the user clicks the checkbox, current date
populates in the bound textbox, all the labels, controls and options either
become disabled or hidden once this checkbox is clicked(to prevent other
changes once Date is set) and then it too becomes diisabled.

I've added the following code to to the form's on current event as well as
the checkbox's after update event. Problem is how do I get the textbox that
iniatiated all of the disables/hides to disiable itself after use without
disabling every checkbox in every record. Checkbox is bound as are all other
controls and form is single form.

Here is where I’m currently at:


If Me.Check675.Value = True Then
Me.Check675.Enabled = False
Me.Check1119.Visible = Check675
Me.Label1118.Visible = False
Me.Label1120.Visible = False
Me.Text1121.Visible = False
Me.Command1122.Visible = False
Me.Command1124.Visible = False
Else
Me.Check675.Enabled = True
Me.Check1119.Visible = True
Me.Label1118.Visible = True
Me.Label1120.Visible = True
Me.Text1121.Visible = True
Me.Command1122.Visible = True
Me.Command1124.Visible = True
End If
 
K

Ken Snell [MVP]

In a continuous forms view, there actually is only one instance of each
control, even though you see "lots of copies". Thus, whatever you do on one
record to disable a control means that all copies of that same control on
the other records also will be disabled.

You are correct to use the form's Current event to disable/enable the
controls as you move from one record to another, based on the checkbox value
if you so desire. Just do it this way:

Private Sub Form_Current()
Me.Check675.Enabled = Not Me.Check675.Value
Me.Check1119.Visible = Me.Check675.Value
Me.Label1118.Visible = Not Me.Check675.Value
Me.Label1120.Visible = Not Me.Check675.Value
Me.Text1121.Visible = Not Me.Check675.Value
Me.Command1122.Visible = Not Me.Check675.Value
Me.Command1124.Visible = Not Me.Check675.Value
End Sub


Note that the above code will not run after you check Check675 true; it will
run only when you move from one record to the next. If you want to disable
as soon as the checkbox is checked, you'll need to have another control on
the record that can receive the focus, and then you'd run code similar to
this on the AfterUpdate event of the checkbox:

Private Sub Check675_AfterUpdate()
Me.OtherControlName.SetFocus
Call Form_Current
End Sub


As for being able to "disable the textbox" part of your question, you'll
need to tell us a bit more about your setup, as it's not obvious to me from
the code you posted what is being done on your form.
 
G

Guest

Ken, many thanks! This site and all of you are great!
Works well...

Just trying to understand why you got rid of the If stament and went with
NOT me... Me referes to "this object"... Simplicity or workability?

Dave
 
K

Ken Snell [MVP]

What I'm doing is using the value of the checkbox itself to set the value of
the other properties.

Me is the object that represents the form, so Me.Check675.Value is the value
that is in the Check675 checkbox control on the form.

By using Not in front of Me.Check675.Value, the value is "negated"; thus, if
Me.Check675.Value has a value of True, Not Me.Check675.Value has a value of
False.

This technique is easy to use for boolean controls; it doesn't require VBA
to run logical tests, VBA just uses the value directly.
--

Ken Snell
<MS ACCESS MVP>
 
G

Guest

Thanks for the explanation...

Ken Snell said:
What I'm doing is using the value of the checkbox itself to set the value of
the other properties.

Me is the object that represents the form, so Me.Check675.Value is the value
that is in the Check675 checkbox control on the form.

By using Not in front of Me.Check675.Value, the value is "negated"; thus, if
Me.Check675.Value has a value of True, Not Me.Check675.Value has a value of
False.

This technique is easy to use for boolean controls; it doesn't require VBA
to run logical tests, VBA just uses the value directly.
 

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