This is the code for a user to log on with password, My question is after the user successful enter password, how do I get the code below to open up a certain name spreadsheet.
The spread sheet name is CASA 212 INVENTORY, that needs to open after a successful login?
Dim Trys As Integer
Private Sub CommandButton1_Click()
SUMBIT BUTTON
Dim FoundIt As Range
Dim Pwd As String
Dim Rng As Range
Dim Role As String
Dim User As String
Dim Wks As Worksheet
Set Wks = Sheet2
Set Rng = Wks.Range("A1").CurrentRegion
User = NameTextBox.Value
If User = "" Then
MsgBox "Please Enter a User ID."
NameTextBox.SetFocus
Exit Sub
End If
Set Rng = Intersect(Rng, Rng.Offset(1, 0))
Set FoundIt = Rng.Find(User, , xlValues, xlWhole, xlByRows, xlNext, False, False, False)
If FoundIt Is Nothing Then
MsgBox "The User '" & User & "' was Not Found in the Access List.", vbExclamation
Exit Sub
End If
Pwd = FoundIt.Offset(0, 1)
If pwdTextBox = "" Then
MsgBox "Please Enter a Password."
pwdTextBox.SetFocus
Exit Sub
End If
If pwdTextBox.Value <> Pwd Then
Trys = Trys - 1
If Trys = 0 Then
Unload Me
Exit Sub
End If
MsgBox "You have Entered an Invalid Password." & vbCrLf _
& "Passwords are case sensitive. Check that the Caps Lock key is not set." & vbCrLf _
& vbCrLf & "You have " & Trys & " attempts to login left.", vbExclamation
pwdTextBox.SelStart = 0
pwdTextBox.SelLength = Len(pwdTextBox)
pwdTextBox.SetFocus
Exit Sub
End If
For Each Opt In Frame1.Controls
If Opt.Value = True And Opt.Caption = FoundIt.Offset(0, 2) Then
Role = Opt.Caption
Exit For
Else
Role = "no match"
End If
Next Opt
If Role = "" Then
MsgBox "Please Select your Role."
Exit Sub
End If
If Role = "no match" Then
MsgBox " Your Role Does Not Match Your Profile.", vbExclamation
Exit Sub
End If
MsgBox "You have sucessfully Logged In."
Unload Me
End Sub
Private Sub UserForm_Initialize()
' Number of log in attempts allowed.
Trys = 5
' Empty NameTextBox
NameTextBox.Value = ""
' Set length to NameTextBox
NameTextBox.MaxLength = 6
' Empty pwdTextBox
pwdTextBox.Value = ""
' Set pwdTextBox Char
pwdTextBox.PasswordChar = "*"
' Empty Option Buttons
tlOptionButton1.Value = False
tmOptionButton2.Value = False
sdmOptionButton3.Value = False
dgmOptionButton4.Value = False
gmOptionButton5.Value = False
' Set Focus on NameTextBox
NameTextBox.SetFocus
End Sub
Bookmarks