Password/Login Code Help

twinpowr

Board Regular
Joined
Mar 14, 2007
Messages
73
Hi Guys,

I have some code listed below, which finds the correct cells and password. the problem is that i can not quite get the logic order correct. this is what should happen.

User enters their login details, if their details are not on the sheet then msgbox"nothing found". If the user is on the system but password wrong, then msgbox "Wrong Password". If username and password correct then check if first login and if so run userform passwordchange. If not first login then load the userform for that user.

a sample of the worksheet would be

A.............. B................C................ D............. E............. F
UserId.....firstname....2ndname......load menu.....Password....1st login
zz12345........John.......Smith........... Admin........anypass......Yes

(Sorry at work can not use htmlmaker)

The passwordchange userform will change the 1st login to No.

Code:
Private Sub CommandButton2_Click()
Dim FindString As String

Dim Rng As Range
'
    FindString = TextBox1.Value
    If Trim(FindString) <> "" Then
        With Sheets("User_Access").Range("A:A")
 '
            Set Rng = .Find(What:=FindString, _
                            After:=.Cells(.Cells.Count), _
                            LookIn:=xlValues, _
                            LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlNext, _
                            MatchCase:=False)
                            If TextBox2.Value = Rng.Offset(, 4) Then
                            MsgBox "Welcome  " & Rng.Offset(, 1) & vbCr & " Password Correct"
                            Load AdminMaster
                            AdminMaster.Show
                            
         Else
                            MsgBox "Wrong Password" & vbCr & "Please Try Again!!"
                            TextBox1.Value = ""
                            TextBox2.Value = ""
   
                                                        
                        If Rng.Offset(, 5) = "yes" Then
                        MsgBox "This is your first login " & vbCr & vbCr & "Please Reset Your Password"
                        Load passwordchange
                        passwordchange.Show
                        
                            If Not Rng Is Nothing Then
                            Application.Goto Rng, True
                            MsgBox "Nothing found"
       
       
          End If
          
          


End If
End If
End With
End If
End Sub

I dont think i am far away with this one, i just can not seem to get the IF order correct.

Any Help would be great.

Thanks in advance.

Ally.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi Guys

I have solved one part of this by sending the code to another procedure called checkfirst after the correct password has been entered.

however i am getting an error if the username entered is not in the list. I will check here on how to write an error handler and post the full code once solved for others.

If anybody has any ideas, would be appreciated. for reference here is the full userform code i am using.

Code:
Option Explicit

Private Sub UserForm_QueryClose(cancel As Integer, CloseMode As Integer)
    If CloseMode = vbFormControlMenu Then
        cancel = True
        MsgBox "Please Use The Exit Button"
            End If
End Sub
Private Sub CommandButton1_Click()
'ActiveWorkbook.Save
Unload Me
End Sub

Private Sub CommandButton2_Click()
Dim FindString As String

    Dim Rng As Range
    FindString = TextBox1.Value
    If Trim(FindString) <> "" Then
        With Sheets("User_Access").Range("A:A")
            Set Rng = .Find(What:=FindString, _
                            After:=.Cells(.Cells.Count), _
                            LookIn:=xlValues, _
                            LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlNext, _
                            MatchCase:=False)
                            
                                                          
                            If TextBox2.Value = Rng.Offset(, 4) Then
                            MsgBox "Password Correct" & vbCr & Worksheets("Team Lists").Range("G1")
                            Call checkfirst
                            
                  Else
                            MsgBox "Wrong Password"
                            
                            If Not Rng Is Nothing Then
                            Application.Goto Rng, True
                      
            Else
                            MsgBox "Nothing found"
End If
End If
End With
End If
End Sub

  
Private Sub UserForm_Initialize()
Call FormatUserForm(Me.Caption)
End Sub
 
Sub checkfirst()
Dim FindString As String

    Dim Rng As Range
    FindString = TextBox1.Value
    If Trim(FindString) <> "" Then
        With Sheets("User_Access").Range("A:A")
            Set Rng = .Find(What:=FindString, _
                            After:=.Cells(.Cells.Count), _
                            LookIn:=xlValues, _
                            LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlNext, _
                            MatchCase:=False)
                            
                            If Rng.Offset(, 5) = "yes" Then
                            MsgBox "This is your first login" & vbCr & "   Please change your Password"
                            Load passwordchange
                            passwordchange.Show
                            Unload Me
                            
                  Else
                            Load AdminMaster
                            AdminMaster.Show
                            Unload Me
                                                  
            
            End If
        
    
    

End With
End If
End Sub

If anyone has a shorter way of doing this then would appreciate some guidance.

Ally.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,280
Members
452,902
Latest member
Knuddeluff

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