Can someone pls verify My code :: combo with password

doran_doran

Registered User.
Local time
Today, 02:17
Joined
Aug 15, 2002
Messages
349
Hi,

Combo box name: cboApprovalStatus

What Do I need ?
I am trying to apply a password when a value is changed in combo box. I think i have to put the code in afterupdate. I put following code but it's not working well. Now, if the a enduser click on drop down and dont change the value then it should not do anything. If end user change the value to new value then it should prompt end user for password and then change the value. if the password is wrong then the msg box pops up "invalid password" and make no changes in drop down value (meaning old value should stay there).

Any help will be appreciated.

Dianna Goldsberg

- - - - My Code - - - -
Private Sub cboApprovalStatus_AfterUpdate()
Dim cmbBefore2 As String
Dim cmbAfter2 As String
Dim strInput As String, strMsg As String

strMsg = "Enter the Password."
cmbBefore2 = Nz(Me.cboApprovalStatus.OldValue, "Null")
cmbAfter2 = Nz(Me.cboApprovalStatus, "Null")

If cmbBefore2 <> cmbAfter2 Then
MsgBox "Status has changed. Please enter the password."
strInput = InputBox(Prompt:=strMsg, Title:="User Info", XPos:=2000, YPos:=2000)

If strInput = "password" Then
change the value in combo box
Else
MsgBox "Incorrect Password OR Password is vacant"
End If
End If

End Sub
 
I'm using the .Tag property to store the current value of the combo box, and then checking the new value against the current value.

It seems that cboApprovalStatus.OldValue is not holding the old value, even in the Before Update event, so there is nothing to compare the new value against. I tried Me.Undo and Cancel=True in the Before Update event but nothing was changing the combo box back to it's original value if the password was incorrect... but this works:

Code:
Private Sub cboApprovalStatus_AfterUpdate()
    Dim strInput As String
    Dim strMsg   As String

    strMsg = "Status has changed.  Please enter the Password."

    If Me.cboApprovalStatus <> Me.cboApprovalStatus.Tag Then
        strInput = InputBox(Prompt:=strMsg, Title:="User Info", XPos:=2000, YPos:=2000)

        If strInput = "Password" Then
            Me.cboApprovalStatus.Tag = Me.cboApprovalStatus
        Else
            Me.cboApprovalStatus = Me.cboApprovalStatus.Tag
            MsgBox "Incorrect Password OR Password is vacant"
        End If
    End If
End Sub


Private Sub Form_Activate()
    Me.cboApprovalStatus.Tag = Me.cboApprovalStatus
End Sub

Notice that in the Form's On Activate event, you want to store the current value of the combo box in the Tag property so your code has something to check the updated value against.
 
Error on Incorrect Password...

Hi Rich,

I am getting an error on incorrect password.

- - - actual error - - -
Run-tim erro '3315':

Field 'tblInvoice.ApprovalStatus' Can't be a zero-length string.

- - - - - - - - - - - - -

The following line is highlighted

Me.cboApprovalStatus = Me.cboApprovalStatus.Tag

When I put my mouse over me.cboapprovalstatus it shows the new value.

when I put my mouse over me.cboapprovalstatus.tag is show "'"" this. which stands for nothing is there.

I think the is not retaining the old value. i try to put me.cboapprovalstatus.tag = me.cboapprovalstatus.oldvalue in form activation.

It did not work. Any suggession.

Regards
Dianna
 
Try setting the default value property of the combo box to whatever you want it to hold upon opening the form, even if it's something like...

"-------"

simply to give the combo box and the Tag property a start value to avoid null problems. I forgot to mention that's what I had done when I was trying out your code.
 
Re-Coding...

Hi Rich,

I was going over your code and combine some of your idea with my old code and now my OLD CODE is working like a charm. Thanks for sharing your idea. I am posting my new code.

Thanks a Bunch for being so prompt and helping me.

Dianna Goldsberg

=========================================================
Private Sub cboApprovalStatus_AfterUpdate()
Dim cmbBefore2 As String
Dim cmbAfter2 As String
Dim strInput As String, strMsg As String

strMsg = "Status has changed. Please enter the Password."
cmbBefore2 = Nz(Me.cboApprovalStatus.OldValue, "Null")
cmbAfter2 = Nz(Me.cboApprovalStatus, "Null")



If cmbBefore2 <> cmbAfter2 Then
'MsgBox "Status has changed. Please enter the password."
strInput = InputBox(Prompt:=strMsg, Title:="User Info", XPos:=2000, YPos:=2000)
If strInput = "password" Then ' change it to whatever you want ur password to be
Me.cboApprovalStatus = cmbAfter2
Else
MsgBox "Incorrect Password OR Password is vacant"
Me.cboApprovalStatus = cmbBefore2
End If
End If
End Sub
=========================================================
 
Last edited:

Users who are viewing this thread

Back
Top Bottom