Hi,
I am using the below code in a username/password form but if the username/password is incorrect the message comes up 'username password is WRONG, but the form closes and access is given to the docuement.
Is there anyway you can make it so if the password is incorrect, you cant access the document?
Code
Private Sub CommandButton1_Click()
Dim username, password As String
Dim Wks As Worksheet
username = TextBox1.Text
password = TextBox2.Text
Select Case TextBox1.Text
Case Is = "Admin"
If TextBox2.Text = "admin" Then
'Unprotect all sheets
For Each Wks In Worksheets
Wks.Unprotect "password"
Next Wks
End If
Case Is = "Data Input"
If TextBox2.Text = "kmart2011" Then
'Protect all sheets
ProtectAllSheets
'Unprotect Sheet1 (Scoring)
'Unprotect Sheet14 (State Safety Score Movement)
Sheet1.Unprotect "password"
Sheet14.Unprotect "password"
End If
Case Is = "Reporting"
If TextBox2.Text = "Reporting" Then
'Protect all sheets
ProtectAllSheets
'Unprotect Sheet14 (State Safety Score Movement)
Sheet14.Unprotect "password"
End If
Case Else
MsgBox "You entered the WRONG info. Please try agian", vbCritical
End Select
Unload Me
End Sub
Display More
Thanks