Lock a combobox after selection

rplohocky

Registered User.
Local time
Today, 13:18
Joined
Apr 13, 2017
Messages
45
Hello, I have been searching online for ever trying to find some thing that will work for my issue.

1. I have a combobox set up on a form with a list to choose from.
.
2. When the user comes to a new record, the combobox would be blank.

3. I have set the properties to "Enabled NO".

4. I created a button next to the combobox which will enable it (password protected code) whenever I need to make a selection.

5. I can then make my selection once enabled.

6. I created another button, to the right side of the combo, which will disable it again.

I am looking for a cleaner way to this. I want to be able to make my selection then have the combo lock down after update.

I need to have the combo box locked all the time, even when its blank. I don't want the user to be to make any selection, the manager should be the only person allowed to make this selection using a password. The ideal scenario would be to click the button, enter the password, make the selection then the combo would lock down again without having a second button to lock it down.
 
What happens if the user accidentally clicks the item below the item they meant to click, and then the combo locks up on them with the wrong value in it? How does the user correct the mistake with all the buttons and locks, and passwords and logins?
Maybe get the authorized user to login at the start of a session, and then save the fact the user is authorized in a table. Then when that user opens the form in question, allow that user to edit the combo freely, without locks or buttons or auto-disable-after-update features?
Mark
 
You need code in a couple of different events.
In the form's Current event and in the Control's lost focus event, you lock the control

Me.cboPickOne.Locked = True

Then in the button, you unlock the combo and set focus to it.

Me.cboPickOne.Locked = False
Me.cboPickOne.SetFocus
 
You need code in a couple of different events.
In the form's Current event and in the Control's lost focus event, you lock the control

Me.cboPickOne.Locked = True

Then in the button, you unlock the combo and set focus to it.

Me.cboPickOne.Locked = False
Me.cboPickOne.SetFocus

This is the code i have in the button on the "On click" event.

Private Sub btnSchedule_Click()
Dim strPassword As String

strPassword = InputBox("Please enter the password: ")
If strPassword = "g3rms" Then
Me!Combo722.Enabled = True
Else
Call MsgBox("The password you entered was incorrect")
End If
End Sub

Where would I insert
Then in the button, you unlock the combo and set focus to it.

Me.cboPickOne.Locked = False
Me.cboPickOne.SetFocus
 
There are better ways of doing this, as has been suggested using the logged in user and setting permissions, although if a manager was to use another persons machine they wouldn't be able to do that then.

Having a single password means it's not very easy to change, and if someone tells someone else pretty soon your protection becomes useless. If you want to have a single password, then look it up from a table at least not in the code, then you can change the password at a seconds notice if you need to, rather than having to change the code and re-issue to everyone.
 
remove first the lock from the combo
and try this code:

Code:
Private Sub Combo_Enter()
    Dim strPassword As String
    If Me.NewRecord Then
        Me.Combo.Locked = False
    Else
        Me.Combo.Locked = False
        strPassword = InputBox("Enter password to Unlock!", "Locked")
        If strPassword <> "arnelgp" Then
            Me.Combo.Locked = True
            MsgBox "Invalid password!"
	    'you may set Focus to other control
	    'to keep him away from this combo
	    ' Me.textbox.SetFocus
        Else
            MsgBox "Combo Unlocked!"
        End If
    End If
End Sub
 
For myself, I would simply display the value.

The button would call a separate form that prompts for user/password then unlocks a combo on the called form to allow data entry. The manager would also have to press a "Save" button to exit the form after having selected the correct value.

From the users perspective, they can "Hit the button" to have the manager log in for the change. No chance they will ever think they can just do the update themselves.

I'd mostly do this to avoid the questions about "Why isn't THIS dropdown working???"
 
Where would I insert
Quote:
Then in the button, you unlock the combo and set focus to it.

Me.cboPickOne.Locked = False
Me.cboPickOne.SetFocus
You said you had a button that you used to unlock the control. I presume it has a click event. That is where the code would go.

PS - it is poor practice to leave your controls with names such as Combo772. Always give them meaningful names BEFORE you start adding code or referencing them. I would still change the name now but now it will be more of a problem because changing the name of the control will not automatically change the name of the event procedures so you will have to do that manually plus fix any compile errors.
 
remove first the lock from the combo
and try this code:

Code:
Private Sub Combo_Enter()
    Dim strPassword As String
    If Me.NewRecord Then
        Me.Combo.Locked = False
    Else
        Me.Combo.Locked = False
        strPassword = InputBox("Enter password to Unlock!", "Locked")
        If strPassword <> "arnelgp" Then
            Me.Combo.Locked = True
            MsgBox "Invalid password!"
	    'you may set Focus to other control
	    'to keep him away from this combo
	    ' Me.textbox.SetFocus
        Else
            MsgBox "Combo Unlocked!"
        End If
    End If
End Sub

Hello, thanks for responding to my question.

I want to maybe simplify this request. All I need is to have my combo locked at all times, when its blank, when its populated, all the time. What I would to do when I come to a new record is have the ability to click a button and make my selection then after my selection is made the combo will lock again.

Right now I do that with 2 buttons, one that unlocks and one that locks again. I just want to do this with out the second button.

I tried your code you sent. I inserted it into the return event on the button but it didn't seem to work and left the combo locked "YES". Did I do something wrong?
 
Two of us are giving you different answers.

Please go back and read #3 again. It tells you the two events that need code to ensure the control is locked. Then it tells you to put two lines of code in your unlock event. I used the .locked property. You can use the .enabled property if you prefer. Currently your unlock code has only one of the lines of code I suggested. I would also add the .setFocus because if the combo never receives the focus, it's lost focus event will never run and so the control will remain unlocked (enabled) when you scroll to the next record.
 
Two of us are giving you different answers.

Please go back and read #3 again. It tells you the two events that need code to ensure the control is locked. Then it tells you to put two lines of code in your unlock event. I used the .locked property. You can use the .enabled property if you prefer. Currently your unlock code has only one of the lines of code I suggested. I would also add the .setFocus because if the combo never receives the focus, it's lost focus event will never run and so the control will remain unlocked (enabled) when you scroll to the next record.

Pat,
Thank you, this is exactly what I was looking for. You told me this in the beginning of this thread but it didn't seem to make sense. After you explained again it worked. Thanks for your help along with all the others that contributed!
 

Users who are viewing this thread

Back
Top Bottom