+ Reply to Thread
Results 1 to 9 of 9

Thread: Userform Login

  1. #1
    Registered User
    Join Date
    06-05-2011
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003
    Posts
    17

    Userform Login

    Hi All,

    I have a document with 10 different tabs all containing Important data and therefore needs protecting.
    I want to have 3 seperate log-in's with each login having diffferent access....

    User 1: Access and Edit entire document
    User 2: Access to edit tab 1 and read only all other tabs
    User 3: Read only entire document.

    I have created the user form with 3 checkboxes plus space for entering a username and password.

    I have worked out the code for 1 username and password but am struggling with the rest.

    Help is appreciated.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Userform Login

    Hello clint182,

    It would help to see what code you already have. If you can post the workbook, that would be best. If not then post the code.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    06-05-2011
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Userform Login

    Hi,
    I have attached the document with the code i have doen so far....
    (For obvious reasons the sheets are blank, but the tabs have their correct names)

    Username: user
    Password: password

    Thanks
    Attached Files Attached Files

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Userform Login

    Hello clint182,

    Thanks for posting the workbook. What user names should I add to the UserForm?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Registered User
    Join Date
    06-05-2011
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Userform Login

    Hi,
    Was thinking
    User 1: Admin
    User 2: Data Input
    User 3: Reporting
    Thanks

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Userform Login

    Hello clint182,

    I used a Select Case statement to validate the user name and password. I also added a module that remove the close "X" from the UserForm. I really get annoyed by clicking the close "X" and being told it doesn't work or to use another button. here is the UserForm code. Change the passwords to what you want. To help keep the worksheet passwords safer, you should lock the VBA project from viewing .
    Sub ProtectAllSheets()
    
      Dim Wks As Worksheet
      
        For Each Wks In Worksheets
          Wks.Protect "password"
        Next Wks
        
    End Sub
    
    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 = "Adimn"
          If TextBox2.Text = "FullAccess" Then
            'Unprotect all sheets
             For Each Wks In Worksheets
               Wks.Unprotect "password"
             Next Wks
          End If
          
        Case Is = "Data Input"
          If TextBox2.Text = "Restricted" Then
            'Protect all sheets
             ProtectAllSheets
            'Unprotect Sheet1 (Master)
             Sheet1.Unprotect "password"
          End If
             
        Case Is = "Reporting"
          If TextBox2.Text = "ReadOnly" Then
            'Protect all sheets
             ProtectAllSheets
          End If
          
        Case Else
          MsgBox "You entered the WRONG info. Please try agian", vbCritical
      End Select
      
      Unload Me
      
    End Sub
    
    Private Sub UserForm_Activate()
      NoCloseX
    End Sub
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  7. #7
    Registered User
    Join Date
    06-05-2011
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Userform Login

    Thanks for your assistamce in solving my problem.

  8. #8
    Registered User
    Join Date
    06-05-2011
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Userform Login

    Hi Again,

    Just one last thing, i have been trying to research the code but had no luck.

    With the current code if the password is incorrect it still allows acess to the document...
    Is there a way to make it that is the username/password is incorrect then it doesnt open the document?

    I am currently using the above formaule.

    Thanks

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Userform Login

    Hello clint182,

    Here is the updated macro. This will close the workbook if the user name and password are incorrect.
    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 = "FullAccess" Then
            'Unprotect all sheets
             For Each Wks In Worksheets
               Wks.Unprotect "password"
             Next Wks
          End If
          
        Case Is = "Data Input"
          If TextBox2.Text = "Restricted" Then
            'Protect all sheets
             ProtectAllSheets
            'Unprotect Sheet1 (Master)
             Sheet1.Unprotect "password"
          End If
             
        Case Is = "Reporting"
          If TextBox2.Text = "ReadOnly" Then
            'Protect all sheets
             ProtectAllSheets
          End If
          
        Case Else
          MsgBox "You entered the WRONG info. Please try agian", vbCritical
          Unload Me
          ActiveWorkbook.Close SaveChanges:=False
      End Select
      
      Unload Me
      
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0