Controls Lock/UnLock Password To Prompt only when UnLocking

  • Thread starter Thread starter niuginikiwi
  • Start date Start date
N

niuginikiwi

Hi,
I've used Allen Browne's Locking bound control codes
(http://allenbrowne.com/ser-56.html) to prevent overwriting data accidentally
and it works fine.
After browsing the newsgroup, I now have this on the onClick event of
command button called cmdLock

Dim bLock As Boolean

If InputBox("Enter password!", "Password Required") <> "password" Then
Exit Sub

bLock = IIf(Me.cmdLock.Caption = "&Lock", True, False)
Me.cmdLock.Caption = IIf(bLock = True, "&UnLock", "&Lock")

Call LockBoundControls(Me, bLock)

This works ok but what happens is everytime I click cmdLock, it is prompting
for password. I only want the password prompt to happen when I am clicking to
UnLock but not to Lock.
How can I arrange the code above to get it only to password prompt when
UnLocking and not when clicking to Lock.

Thanks in advance
 
Set bLock first then if it's true, ask for a password...

bLock = IIf(Me.cmdLock.Caption = "&Lock", True, False)
If bLock Then
If InputBox("Enter password!", "Password Required") <> "password" Then
Exit Sub
End If
End If
Me.cmdLock.Caption = IIf(bLock = True, "&UnLock", "&Lock")
Call LockBoundControls(Me, bLock)


that wasn't that hard...

I would recommend the use of a proper exit procedure btw. hth
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
Thanks Jack.
It was indeed so simple but I maybe still sleeping as it is early morning
here in NZ ;-) Thanks for your help.
One thing was I wanted to happen the opposite of what the effect was on your
suggestion so I put a "If Not bLock ......" to reverse the effect and is
working fine. Here is the code if anyone will need it:
Dim bLock As Boolean

bLock = IIf(Me.cmdLock.Caption = "&Lock", True, False)

If Not bLock Then
If InputBox("Enter password!", "Password Required") <> "password" Then
Exit Sub
End If
End If
Me.cmdLock.Caption = IIf(bLock = True, "&UnLock", "&Lock")
Call LockBoundControls(Me, bLock)
 
Back
Top