Clear checkmark in CheckBox

  • Thread starter JAdams via AccessMonster.com
  • Start date
J

JAdams via AccessMonster.com

I have a checkbox in a single form and I need to remove the 'checkmark' based
on the click event on the following checkbox object 'ManagerSignature.
What I'm trying to achieve is as follows:
This check box is used to identify that the form has been signed by a manager.
What I need to happen is, if the current user CurrentUser( ) places a
checkmark in this object and the current user is not "Luella" then a message
box will pop up and say "You do not have permissions to sign". At that point
I need the program to CLEAR the checkmark from the 'ManagerSignature' check
box once the user clicks 'ok to the message box.
This is the code that I have built into the click event of the
ManagerSignature checkbox object.

Private Sub ManagerSignature_Click()
If Me.ManagerSignature = True And CurrentUser() <> "Luella" Then
MsgBox "You do not have permissions to sign"

Else
If Me.ManagerSignature = False Then
Me.ManagerSignatureLine = ""
End If
End If

Note: not sure of the code to clear the checkmark and where it should be
placed in the above code.

Thanks for you help
 
R

Rob Parker

Rather than using the Click event of the checkbox, use the BeforeUpdate
event, which you can cancel. The following should work:

Private Sub ManagerSignature_BeforeUpdate(Cancel As Integer)
If Me.ManagerSignature = True And CurrentUser() <> "Luella" Then
MsgBox "You do not have permissions to sign"
Cancel = True
Me.ManagerSignatureLine = ""
End If
End Sub

This will also clear the ManagerSignatureLine entry. If that is an editable
textbox control, then you might prefer to restore its previous value, rather
than clearing it; you can do so by using:
Me.ManagerSignatureLine = Me.ManagerSignatureLine.OldValue

Note also that clearing the entry by setting it to a zero-length string
(ZLS) will allow "blank" entries in the underlying table to be either Null
(either because nothing has been entered, or because an entry has been
deleted) or a ZLS; if you are using Is Null as a criteria in any query you
may not get the result you expect, since a ZLS is not null. You can clear
the entry by setting it to null, if that suits your purposes better:
Me.ManagerSignatureLine = Null

HTH,

Rob
 
J

John W. Vinson

I have a checkbox in a single form and I need to remove the 'checkmark' based
on the click event on the following checkbox object 'ManagerSignature.
What I'm trying to achieve is as follows:
This check box is used to identify that the form has been signed by a manager.
What I need to happen is, if the current user CurrentUser( ) places a
checkmark in this object and the current user is not "Luella" then a message
box will pop up and say "You do not have permissions to sign". At that point
I need the program to CLEAR the checkmark from the 'ManagerSignature' check
box once the user clicks 'ok to the message box.
This is the code that I have built into the click event of the
ManagerSignature checkbox object.

Private Sub ManagerSignature_Click()
If Me.ManagerSignature = True And CurrentUser() <> "Luella" Then
MsgBox "You do not have permissions to sign"

Else
If Me.ManagerSignature = False Then
Me.ManagerSignatureLine = ""
End If
End If

Note: not sure of the code to clear the checkmark and where it should be
placed in the above code.

Thanks for you help

I'd suggest not using the checkbox's Click event at all, but rather its
BeforeUpdate event - which can be cancelled.

Private Sub ManagerSignature_BeforeUpdate(Cancel as Integer)
If Me.ManagerSignature And CurrentUser<> "Luella" Then
MsgBox "You do not have permission to sign"
Cancel = True
End If
End Sub

This (as written) will only let Lulla check the box, but anyone can uncheck
it.
 

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