• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Match login details to cells in file

JeroenCreemers

New Member
Dear All,

I've created a simple login form in with VBA that works fine, but i would like to add an extra verification.

Currently typing the right username and password is good enough to open the file. But what I want as extra verification is that the username also needs to equal cell C2 on sheet 2. I have given it a range name "Email". The same for the password that's also on sheet 2 but then in cell C9.

If possible I would also like add a verification that checks if the year equals the year on sheet 2 in cell C11.

Currently this is my code:
Code:
Private Sub LoginButton_Click()

If Me.Username.Value = "admin@admin.com" Then
    If Me.Password.Value = "ABCDEFGH" Then
        LoginFlag = True
        Unload Me
        Exit Sub
    End If
End If

MsgBox "Sorry, Incorrect Login Details"

End Sub

And i'm trying to get this:

Code:
Private Sub LoginButton_Click()

If Me.Username.Value = "admin@admin.com" and equals to sheet2 cell C2 Then
    If Me.Password.Value = "ABCDEFGH" and equals sheet2 cell C9 Then
Year = "2018" and equals to sheet2 Cell C11       
LoginFlag = True
        Unload Me
        Exit Sub
    End If
End If

MsgBox "Sorry, Incorrect Login Details"

End Sub

I hope somebody can help me.

Kind regards,
Jeroen

MOD EDIT: Added CODE tags. Please use CODE tags to post your code.
 

Attachments

  • VBA code.xlsm
    22.7 KB · Views: 11
Last edited by a moderator:
Zoiets?
Code:
Private Sub LoginButton_Click()
If Username.Value = "admin@admin.com" And Sheets("Sheet2").Range("C2").Value = Username.Value Then
    If Password.Value = "ABCDEFGH" And Sheets("Sheet2").Range("C9").Value = Password.Value Then
        If Sheets("Sheet2").Range("C11").Value = "2018" Then
LoginFlag = True
Unload Me
Exit Sub
End If
    End If
        End If
MsgBox "Sorry, Incorrect Login Details", vbCritical, "Error"

End Sub
 
Last edited:
Back
Top