12 year old post revived!

Arie Bos

Board Regular
Joined
Mar 25, 2016
Messages
224
Office Version
  1. 365
Platform
  1. 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:
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?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
IMO this event procedure ...
Rich (BB code):
Private Sub btnSettings_Click()
    frm01_UserPin.Show vbModal
End Sub

should look like this:
VBA Code:
Private Sub btnSettings_Click()
    ShowSettingsForm
End Sub
 
Upvote 0
Thanks GWteB to answer one of my questions again.
I replaced the line with your suggestion, but nothing changed. it seems the ShowSettingForm() proc is simply not called for.
 
Upvote 0
Would recommend to set some break points on each procedure entry within VBE and have the Locals Window open. Run the code again and step through it (F8 key). That's the only way to determine what's going on.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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
Back
Top