Auto Log In

tigerdel

Board Regular
Joined
Oct 13, 2015
Messages
145
Office Version
  1. 365
Platform
  1. Windows
Hi All

I have Log In Security within a Workbook which is activated by Clicking a button [CommandButton2]. However, what I need is, if a User clicks the other button [CommandButton1] then it will open the workbook and all sheets [except Admin & Lists] so they can view the content.

I cannot work this out at all

Anyhelp gratefully received

Thanks

Derek
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Code:
Private Sub Cancel_Click()


    Unload Me


End Sub


Private Sub OK_Click()


Dim c               As Object
Dim UserName        As String
Dim Password        As String
Dim MyError         As Integer
    
    'Assign UserName to a variable
    UserName = UserVerification.UserName.Text
    
    'Assign Password to a variable
    Password = UserVerification.Password.Text
    
    'Specify the sheet and range to look up the UserName
    With Sheets("UserNames").Range("A:A")
        Set c = .Find(What:=UserName, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=True)
    End With
    
    'If UserName cannot be found
    If c Is Nothing Then
        MsgBox "The username you have inputted is invalid, please try again.", vbCritical, "Incorrect UserName"
        Exit Sub
    End If
    
    'If Password is correct
    If Password = Sheets("UserNames").Range(c.Address).Offset(0, 1).Text Then
        ThisWorkbook.Unprotect Password:="Password"
                
        'If the sheet to make visible is not in the workbook an error will occur
        'If there is no error then make that sheet visible
        On Error Resume Next
        Sheets(Range(c.Address).Offset(0, 2).Text).Visible = True
        MyError = Err
        On Error GoTo 0
        ThisWorkbook.Protect Password:="Password", Structure:=True
        
        'If there was an error let the user know to try again.
        If MyError <> 0 Then
            MsgBox "The sheet specified could not be shown, please contact your system administrator.", vbCritical, "Sheet Specification Error"
            Exit Sub
        End If
        Else
        
        'If the password is incorrect let the user know to try again
        MsgBox "The password you have specified is incorrect, please try again.", vbCritical, "Incorrect Password"
        Exit Sub
    End If
    
    'Dismiss the userform
    Unload Me


End Sub

Download workbook : https://www.amazon.com/clouddrive/share/VSC7ylxUGN8UTtcjk0ShsUgpwHpyavG9d7JICPZf3CV
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top