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