Results 1 to 11 of 11

Password protecting UserForm?

Threaded View

  1. #1
    Registered User
    Join Date
    03-13-2008
    Posts
    52

    Password protecting UserForm?

    Private Sub cmbValidate_Click()
    Dim FindR As Range
    Dim FindR2 As Range
    On Error Resume Next
    Set FindR = Sheet9.Range("D").Find(What:=UserForm2.tbxUser.Value, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext)
    Set FindR2 = Sheet9.Range("E").Find(What:=UserForm2.tbxPW.Value, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext)
    On Error GoTo 0
    Dim sMsg As String, sTitle As String, sStyle As String
    Dim iCounta As Integer
    iCounta = Me.tbxGoes.Value
    sTitle = "Hub Access Manager - Invalid"
    sMsg = "You have entered an incorrect Username and/or Password" & vbNewLine & "Please try again using your exact details." & vbNewLine & "You have " & (3 - iCounta) & " attempts remaining."
    sStyle = vbOKOnly + vbExclamation
    If iCounta < 3 Then
    If Me.tbxUser.Value <> FindR Or Me.tbxPW.Value <> FindR2 Then
    MsgBox sMsg, sStyle, sTitle
    With Me
    tbxUser.Value = vbNullString
    tbxPW = vbNullString
    tbxUser.SetFocus
    tbxGoes.Value = iCounta + 1
    End With
    Else
    Sheet9.Range("B1").Value = UserForm2.tbxUser.Value
    Unload Me
    UserForm1.Show
    UserForm1.Label226 = Sheet9.Range("B1").Value
    End If
    ElseIf iCounta > 2 Then
    MsgBox "You have tried three time incorrectly. Hub Access Manager will now close the Hub.", vbOKOnly + vbExclamation, "Hub Access Manager: Closing"
    ActiveWorkbook.Close SaveChanges:=False
    End If
    End Sub
    I am using the above code to password-protect UserForm1 by using UserForm2. Although I know these password protect systems are easily surpassed I need some level of protection in the UserForm as it contains confidential information and it's been requested from a higher level.

    I have highlighted in red where I am encountering the dreaded [91] error "Object variable or With block variable no set".

    Simply put, I have a small range of Usernames and Passwords in range D:E (D being Usernames, E being passwords). I want the password checker to search through the Usernames and passwords and if the relevant Username and Password entered by the user isn't found then I want them to be notified and they have 2 further attempts. After the third attempt the program will simply exit. If they enter a correct Username and Password combination, then they are directed to UserForm1.

    The code above worked like a dream for the counter (which advises the user which try they are on) and for putting a "Logged in as: XXX" message on UserForm1 once successfully entered however only for a singular set Username/Password. Short of giving every one of the expected 300 or so users of this program a copy of their own and changing every bit of code for each user, is there anyway I can edit the above code to make it work?

    Many thanks in advance for any help.

    For your ease of helping, please find a copy of the workbook via the link below - please ignore all the random details in each of the sheets, only the UserForm is important

    http://www.nippyzip.com/uploads/080519105604-01993.zip

    ~Liam
    Last edited by LiamPotter; 05-19-2008 at 10:58 AM.

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.6.0 RC 1