disallow state change of check box

A

alekm

Hi,
if the check box is clicked how can I disallow change of its state based on
certain terms...
Thanx

alekmil
 
S

Stuart McCall

alekm said:
Hi,
if the check box is clicked how can I disallow change of its state based
on
certain terms...
Thanx

alekmil

If <certain terms> Then
Checkbox.Enabled = False
Else
Checkbox.Enabled = True
End If

It's best to do this before the checkbox is clicked (say the lostfocus event
of the previous control or something like that)
 
A

alekm

How do I know what control is previos????

Stuart McCall said:
If <certain terms> Then
Checkbox.Enabled = False
Else
Checkbox.Enabled = True
End If

It's best to do this before the checkbox is clicked (say the lostfocus event
of the previous control or something like that)



.
 
J

Jon Lewis

That's exactly what Enabled does. If .Enabled = True the check box is
greyed out and you can't change it.

If the context is a single form view Form then use the Current Event for the
code
If <certain terms> Then
Checkbox.Enabled = False
Else
Checkbox.Enabled = True
End If

If the conditions change (e.g. you update another control) use the relevent
After Update event to set the Enabled state of the Check Box.

HTH
 
A

alekm

I don't want to disable check box because there are users allowed to change
it. There are user who are not to allowed to change its state . I want to
check them in before update event and if user is not allowed changing check
box I want to put there Cancel = true.
The questio is: As soon Cancel = true is executed I fall in loop. Event
procedure is execute over and over again. Why is that?
 
P

PieterLinden via AccessMonster.com

alekm said:
I don't want to disable check box because there are users allowed to change
it. There are user who are not to allowed to change its state . I want to
check them in before update event and if user is not allowed changing check
box I want to put there Cancel = true.
The questio is: As soon Cancel = true is executed I fall in loop. Event
procedure is execute over and over again. Why is that?
That's exactly what Enabled does. If .Enabled = True the check box is
greyed out and you can't change it.
[quoted text clipped - 39 lines]
oh, now you tell us. Check the user's NT Login in the OnCurrent event and
disable the control if it's not someone who is allowed to make changes. or
give the users a different front end with that field disabled.
 
J

Jon Lewis

I think this is the nature of a CheckBox in that the act of getting focus
changes it so BeforeUpdate kicks in whilst the box still has the focus.
Cancel = True then resets it this triggers another BeforeUpdate event as
soon as focus goes to another control control and so-on.

So basically you can't use Before Update for this.

But do I gather that my previous suggestion won't work because you are
sharing the same 'front end' with multi-users? This isn't a good idea. You
should split the database into a data file that you share and a separate
front end for each user.
If you really don't want to do this then try the Mouse Down event

If <Your Terms> Then
MsgBox "You can't change this "
Me.Checkbox.Locked = True
Else
Me.Checkbox.Locked = False
End If

(You can't disable it as it has the focus)

HTH
 
D

Dirk Goldgar

Jon Lewis said:
I think this is the nature of a CheckBox in that the act of getting focus
changes it so BeforeUpdate kicks in whilst the box still has the focus.
Cancel = True then resets it this triggers another BeforeUpdate event as
soon as focus goes to another control control and so-on.

So basically you can't use Before Update for this.

Yes, you can, but you have to undo the control's update as well as
cancelling it:

Private Sub chkYourCheckbox_BeforeUpdate(Cancel As Integer)

If <some condition> Then
Cancel = True
Me.chkYourCheckbox.Undo
End If

End Sub

I agree with you, Jon, that it doesn't make sense to even to enable the
check box if the user isn't allowed to check it. Your proposal to enable or
disable the check box in the form's Open event, after checking the current
user's authorization, makes perfect sense, and should work regardless of
whether the database is split or not.
 
J

Jon Lewis

Yes you're right about that of course Dirk, but yes the disabling approach
is much better.

Jon
 
A

Amy E. Baggott

You could also disable it in the form's On Open or On Current event based on
the username.
 

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