Code:
Dim IdCorrect As Boolean
Dim Attempts As Integer

Private Sub cmdEnter_Click()
Attempts = 0

If txtUser = "HornsbyB" And txtPass = "abcde" Then
IdCorrect = True
Form2.Visible = True
Login.Visible = False
'closes login screen and opens main program
ElseIf txtUser = "ClaptonN" And txtPass = "fghij" Then
IdCorrect = True
Form2.Visible = True
Login.Visible = False
ElseIf txtUser = "ZeppelinF" And txtPass = "klmno" Then
IdCorrect = True
Form2.Visible = True
Login.Visible = False
If IdCorrect = False Then Attempts = Attempts + 1
'if the user gets the username or password wrong the value adds 1 attempt
End If
If Attempts = 3 Then
    MsgBox "No more attempts"
    End
    End If
The aim of this code is to block the user and end the program when the user has made 3 attempts. When I run the program it does not register any of the attempts to close it. My friend has done the same thing but using a text box value rather than storing it so the text box adds 1 to its value each time. This seems to work. What am I doing wrong? As I see it its exactly the same process but storing it as a physical value rather than a integer.