Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Give this a try. It's "rough" code, and certainly needs refining, but it works, and should give you some ideas.</p> <p>This goes in UF_Encoding</p> <pre><code>Option Explicit 'UF_Encoding form Private msLBox As String Private msUser As String Public Property Let psUser(s As String) msUser = s End Property Public Property Get psLBox() As String psLBox = msLBox End Property Private Sub LB_Options_AfterUpdate() msLBox = Me.LB_Options.Value If Me.LB_Options.Value = "Log out" Then Me.Hide Me.LB_Options.Visible = False UF_Login.TB_Username.Value = "" UF_Login.TB_Password.Value = "" ElseIf Me.LB_Options.Value = "Change Password" Then Me.Hide Me.LB_Options.Visible = False UF_Changepass.TB_User.Value = "" UF_Changepass.TB_Newpass.Value = "" UF_Changepass.TB_Oldpass.Value = "" ElseIf Me.LB_Options.Value = "Exit" Then Me.Hide ' wbDbase.Save ' wbDbase.Close ' wbEncoding.Save ' wbEncoding.Close ' Unload UF_Login ' Unload UF_Changepass ' Unload Me End If End Sub Private Sub UserForm_Activate() Me.L_User.Caption = "Welcome " &amp; msUser &amp; "!" &amp; " You are logged in." Me.TB_Operator.Text = msUser msLBox = "" 'reset each time form re-entered Me.LB_Options.Visible = True End Sub Private Sub UserForm_Initialize() Me.LB_Options.AddItem "Log out" Me.LB_Options.AddItem "Change Password" Me.LB_Options.AddItem "Exit" Me.TB_ESN_IMEI.Value = "" Me.CB_PrimaryCode.Value = "" Me.CB_SecondaryCode.Value = "" Me.TB_Remarks.Value = "" Me.TB_ESN_IMEI.SetFocus End Sub </code></pre> <p>This goes in UF_Login</p> <pre><code>Option Explicit 'UF_Login form Private msUser As String Public Property Get psUser() As String psUser = msUser End Property Private Sub CBu_Login_Click() Dim ws As Worksheet, rng As Range, lrow As Long, find_value As String Dim cel As Range Set ws = ThisWorkbook.Sheets("UserName") lrow = ws.Range("A" &amp; ws.Rows.Count).End(xlUp).Row Set rng = ws.Range("A2:A" &amp; lrow) find_value = Me.TB_Username.Value Set cel = rng.Find(What:=find_value, After:=ws.Range("A2"), LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False) If Not cel Is Nothing Then If Me.TB_Password.Value = cel.Offset(0, 1).Value Then msUser = cel.Offset(0, 2).Value 'save user name Me.Hide Else MsgBox "Invalid Username/Password" End If Else MsgBox "Invalid Username/Password" End If End Sub </code></pre> <p>This goes in UF_Changepass</p> <pre><code>Option Explicit 'UF_Changepass form Private Sub CMDok_Click() Dim ws As Worksheet, rng As Range Set ws = ThisWorkbook.Sheets("UserName") ws.Columns("B:B").Find(Me.TB_Oldpass, , xlValues, xlWhole, , , False).Value = Me.TB_Newpass Me.Hide End Sub Private Sub UserForm_Click() </code></pre> <p>This code goes in a regular module</p> <pre><code>Option Explicit Dim fLogin As UF_Login Dim fEnc As UF_Encoding Dim fChg As UF_Changepass Sub main() Dim s As String ' initialize all 3 forms Set fLogin = New UF_Login Set fEnc = New UF_Encoding Set fChg = New UF_Changepass fLogin.Show '1st time ' re-display main form until done Do fEnc.psUser = fLogin.psUser 'pass user name to main form fEnc.Show s = fEnc.psLBox 'get listbox value If s &lt;&gt; "Exit" Then showAuxForms s Loop Until s = "Exit" ' done with forms Unload fLogin Unload fEnc Unload fChg Set fLogin = Nothing Set fEnc = Nothing Set fChg = Nothing End Sub Sub showAuxForms(s As String) If s = "Log out" Then fLogin.Show ElseIf s = "Change Password" Then fChg.Show End If End Sub </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload