Hi All,
Back again for some help if someone would be so kind. I recently had some help getting some password protection coding in place for my project. It seemed to work on my gutted sample book I provided, but now I have it in my actual project, it doesn't seem to work. Here is a brief operational rundown of what I am trying to accomplish:
User selects a function out of a group of option boxes. This reveals another set of options where the user picks a work unit. Based on the work unit selection, the user provides a work unit specific password. If the user doesn't key in the proper password for their work unit selection, they will not be able to open the option from the function group. If the password is correct, the code should only allow the user to activate the function specific to their work unit.
Example: 3 functions, and 3 work groups...each workgroup share the same functions however they are unique to themselves. EEG (work unit) Report Occurence, View Logsheet, Goto Report Manager (shared function) should not be accessible by the EMU (work unit) which would also have the same functions. Clear as mud, right?
Anyway, for reasons I can't figure out, the password code seems to allow anything to pass as long as the 2 option selections are made. I am not getting error messages and I don't think the code is hanging up.
Private Sub Click_Submit_Click()
' sel_user :
Dim sel_user As String, entered_pass As String
Dim sel_user_row As Integer
Dim chkIfAdmin As Boolean
'
' So that the screen doesn't flick
' while running macro
'
Application.ScreenUpdating = False
'
' Shows the super-hidden sheet
'
Sheet6.Visible = xlSheetVisible
'
' Getting user name based on selection
'
If opteeg.Value = True Then
sel_user = opteeg.Caption
ElseIf optemu.Value = True Then
sel_user = optemu.Caption
ElseIf optiom.Value = True Then
sel_user = optiom.Caption
End If
If sel_user = "" Then
chkIfAdmin = (MsgBox("Are you trying to login as an administrator?", vbQuestion + vbYesNo, "Admin?") = vbYes)
If chkIfAdmin = True Then
sel_user = "Master"
Else
MsgBox "No user selected. Please select a user to proceed further"
Exit Sub
Exit Sub
End If
' Assigning password to variable
entered_pass = TB_Logon.Text
If entered_pass = "" Then
MsgBox "No password provided. Field cannot be empty"
Exit Sub
End If
' Loops through the available users in the list
For i = 1 To Range("Users").Count
' checks if user name matches
If sel_user = Range("Users").Cells(i, 1).Value Then
' Gets the next column value in the same row
' which is the password
If entered_pass = Cells(i + 1, 2).Value Then
End If
End If
Next i
Application.ScreenUpdating = True
End If
Call Selectme
End Sub
I also attempted to do case statement for handling the choices picked in the 2 option groups. As you will note, my VBA skills are lacking. Hopefully you can get a feel for the direction I was wanting to go with this. Here is what I came up with:
Private Sub Selectme()
Select Case True And True
Case optocc, opteeg
UF_Occurence.Show
UF_Occurence.TextBox1.Text = "EEG"
UserForm1.Hide
Case optocc, optemu
UF_Occurence.Show
UF_Occurence.TextBox1.Text = "EMU"
UserForm1.Hide
Case optocc, optiom
UF_Occurence.Show
UF_Occurence.TextBox1.Text = "IOM"
UserForm1.Hide
Case optlog, opteeg
Sheet4.Activate
UserForm1.Hide
Case optlog, optemu
Sheet3.Activate
UserForm1.Hide
Case optlog, optiom
Sheet2.Activate
UserForm1.Hide
Case optman, opteeg
UF_RP_Launch.Show
UF_RP_Launch.RL_TBWU.Text = "EEG"
UserForm1.Hide
Case optman, optemu
UF_RP_Launch.Show
UF_RP_Launch.RL_TBWU.Text = "EMU"
UserForm1.Hide
Case optman, optiom
UF_RP_Launch.Show
UF_RP_Launch.RL_TBWU.Text = "IOM"
UserForm1.Hide
End Select
End Sub
I am attaching my project if anyone would care to take a closer look. My coding is scattered throughout the project, but the majority of my issues are with the code placed on userform1.
Thank you all for the loads of help you provide all of us.
Patrick
Bookmarks