Open HomePage from Login Dialog

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Open HomePage from Login Dialog

Post by adam »

Hi anyone,

I’m having a workbook which has two forms. One I have named as frmLoginDialog and the other I have named as frmHomePage.

I have applied the following code to the form frmLoginDialog

Code: Select all

Private Sub cmbValidate_Click()
Dim sPW As String, sUser As String
Dim sMsg As String, sTitle As String, sStyle As String
Dim iCounta As Integer
     
 sUser = "adam"
 sPW = "adam"
 iCounta = Me.tbxGoes.Value 'set tbxUser visible prpety to false before using
 sTitle = "Incorrect Password"
 sMsg = "You have entered an incorrect Username or Password" _
 & vbNewLine & "Try again" & vbNewLine & _
 "You have " & (3 - iCounta) & " goes left"
 sStyle = vbOKOnly + vbExclamation
 If iCounta < 3 Then
   If Me.tbxUser.Value <> sUser Or Me.tbxPW.Value <> sPW Then
   
    MsgBox sMsg, sStyle, sTitle
    With Me
    tbxUser.Value = vbNullString
    tbxPW = vbNullString
    tbxUser.SetFocus
    tbxGoes.Value = iCounta + 1
    End With
    
     Else
     MsgBox "Correct Information Entered.  Please Proceed.", vbOKOnly + vbInformation, "Correct Information entered."
            Sheet2.Activate
            Unload Me
        End If
        ElseIf iCounta > 2 Then
        MsgBox "You have tried three time incorrectly. WorkBook will now close" _
        , vbOKOnly + vbExclamation, "Warning"
       ' ActiveWorkbook.Close SaveChanges:=False 'close without saving
         End If
End Sub

Private Sub UserForm_Initialize()

Me.tbxGoes.Value = 1
End Sub
What I want is to hide the frmLoginDialog and open the frmHomePage, when I click the Validate Button after writing the password and the username.

I did use the followings lines above the endsub, but I couldn’t make them work.
Me.Hide
frmHomePage.Show

Any help would be kindly appreciated.

Thanks in advance.

Regards
Adam
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Open HomePage from Login Dialog

Post by HansV »

You must delete the lines

Sheet2.Activate
Unload Me

and insert the lines

Me.Hide
frmHomePage.Show

in their place.
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Open HomePage from Login Dialog

Post by adam »

Thank you Hans.

The change in code works the way as I want.
Your help has made a difference in my project & I really appreciate it.

Regards
Adam
Best Regards,
Adam