This code is supposed to basically limit the number of attempts a user has at changing the pc password. It is then meant to invoke to unload function. Anyone have any ideas why it isnt working and it is allowing many many tries.
Once the old pwd is correct it does what it is meant to.

It just doesnt unload when the attempts >=3 (which is the limit i set)

Any help is appreciated. This on has me stumpted.

Private Sub cmdchange_Click()
'Record how many attempts have been made.
Static iTries As Integer

'Check the user's password to the one that has been saved.
If MMain.Encrypt(txtOldPassword.Text) = MMain.Password Then
If txtNewPassword.Text = txtConfirm.Text Then
'Save the new password.
MMain.Password = txtNewPassword.Text

MsgBox "Password changed.", vbInformation

Unload Me
Else
iTries = iTries + 1
If iTries >= MAX_TRIES Then
'The user did not enter the password in the allowed number of tries.
Unload Me
Else
MsgBox "Wrong password. Try again.", vbExclamation
End If

'Highlight the old password.
With txtOldPassword
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
End If
End If
End Sub


Any hints?

regards
Morpheus.