To enter pin or password to change checkbox value in MS Access form

hafiff

Board Regular
Joined
Feb 5, 2008
Messages
62
I created a form of task and the completed task will be identified by a checkbox as clicked. The field is Task Completed: "checkbox". If the box is checked, then it is completed. The checkbox has to be done by a manager so I need to have to build a pop-up form (frm_Pin) with VBA code attached to it. The frm_Pin will pop - up when the checkbox is click (click event) on the checkbox.

Here is the vba code I created:
Private Sub...
Pin.setfocus
If Pin ="123" then
If Me.ChkBox = false then
Me.ChkBox = True
End If
Else
MsgBox "Pease re-enter pin"
End if
End sub

Question
I want the vba code to be able to see what is the current value. If yes (true), then change to no (false). How to insert loop code into the code above?

Thanks
 
Last edited:

Some videos you may like

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

stumac

Active Member
Joined
Jul 16, 2010
Messages
471
Change it to the Before Update event and cancel if the pin is incorrect.

Code:
If me.pin <> "123" then
Cancel = True
Msgbox "Incorrect pin, please re-enter"
Me.pin.setfocus
End if

This way if the pin is correct it will update as expected.
 
Last edited:

hafiff

Board Regular
Joined
Feb 5, 2008
Messages
62
Thanks for the idea of putting the code on before update. However, I received an error that highlighted the me.pin.setfocus and the form was frozen until I went to stop the code from running.

What I did to your code is adding a field named "pin" and name of control is also pin. I think your idea is to make sure that "123" in entered first on pin field. if it is not "123", then cancel the change and go to pin field. The problem is the cursor does not move to pin field. Do you think that I need to write something else beside cancel = true?

Thanks
 

stumac

Active Member
Joined
Jul 16, 2010
Messages
471
just seen pin is on second form - maybe remove the second form and use an input box.... something like:

Code:
Dim Pin As String
Dim chkPin As String: chkPin = "123"
Dim Resp

Do While Pin <> chkPin
    Pin = InputBox("Please enter pin", "Pin required")
    If Pin = vbNullString Then GoTo DontUpdate
    If Pin = chkPin Then Exit Sub 'If it is correct it will exit this loop and value updated
    Resp = MsgBox("Incorrect Pin, Retry?", vbYesNo + vbQuestion, "Pin required")
    If Resp <> vbYes Then GoTo DontUpdate
Loop
     
DontUpdate:
Cancel = True 'If it gets to here the update of the value is cancelled
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,128,129
Messages
5,628,865
Members
416,347
Latest member
AT2021

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top