Arie Bos
Board Regular
- Joined
- Mar 25, 2016
- Messages
- 224
- Office Version
- 365
- Platform
- Windows
In Userform as username and password login screen, Mikerickson gives a nice code to ask for username and pw from a predefined UserRange. I tried it out it in a new workbook and it worked very well.
Now, my question is as follows:
I tried to implement this in another workbook with 15 userforms. In one form the (known) user can chance product sales prices, and I would like to use Mike's code before one could make those changes.
So, from my opening screen, there is a button to open the form with combo and textbox for username and pw, which works well, but after entering PW (right or wrong) nothing happens.
I have adjusted mikerickson's code as follows:
in a normal module:
in the code from the opening-user form:
Then frm01_UserPin opens correctly with the following code:
Although it worked fine as a stand alone macro in a separate workbook, it does not return the MsgBox (in case of wrong password) nor the frm01_Setting form. Nothing actually happens after filling in the password, whether right or wring.
What am I missing to trigger the outcome of sub ShowSettingsForm() from the headless module?
Now, my question is as follows:
I tried to implement this in another workbook with 15 userforms. In one form the (known) user can chance product sales prices, and I would like to use Mike's code before one could make those changes.
So, from my opening screen, there is a button to open the form with combo and textbox for username and pw, which works well, but after entering PW (right or wrong) nothing happens.
I have adjusted mikerickson's code as follows:
in a normal module:
VBA Code:
Function UserKnowsPassword() As Boolean
frm01_UserPin.Show
UserKnowsPassword = (frm01_UserPin.Tag = "True")
Unload frm01_UserPin
End Function
Sub ShowSettingsForm()
If UserKnowsPassword = True Then
frm01_Settings.Show vbModal
Else
MsgBox "user did not match password"
End If
End Sub
in the code from the opening-user form:
VBA Code:
Private Sub btnSettings_Click()
frm01_UserPin.Show vbModal
End Sub
Then frm01_UserPin opens correctly with the following code:
VBA Code:
Option Explicit
Private Sub UserForm_Initialize()
CommandButton1.Caption = "Enter"
TextBox1.PasswordChar = Chr(42)
ComboBox1.List = Range("UserRange").Value
End Sub
Private Sub CommandButton1_Click()
If 0 <= ComboBox1.ListIndex Then
Rem case sensitive
Me.Tag = CStr(Range("UserRange").Find(ComboBox1.Text).Offset(0, 1).Value = TextBox1.Text)
End If
Me.Hide
End Sub
Private Sub ComboBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
KeyAscii = 0
End Sub
Although it worked fine as a stand alone macro in a separate workbook, it does not return the MsgBox (in case of wrong password) nor the frm01_Setting form. Nothing actually happens after filling in the password, whether right or wring.
What am I missing to trigger the outcome of sub ShowSettingsForm() from the headless module?