3 conditions if else statement.

M

maxifire

Hi Guys,

I'm currently having troubles to fufill the 3 conditions in the if els
statement which I have coded.

This if-else statement is used in the password checking system wher
the usernames and passwords are all stored in a spreadsheet. Beside
usernames and passwords, there are 2 groups where users belong to. The
are 'A' - Administrators, and 'N' - Normal Users.

In the if-else statement, I plan to code it in such a way that it wil
scan through the spreadsheet looking for the username and once i
matches, it will offset by (0, 1) to compare the password. After which
the code should offset again to check for the usergroup so as to show
different menu between administrators and users.

The following code which I coded, unfortunately does not work due t
some reasons. :mad: :( Will be really grateful if someone coul
assist.

Lastly, sorry for the wrong post.


Regards,
Kenneth

---

Sub OkBtn_Click()
Dim a As Integer
Dim Name As String
Dim Pass As String
Dim Group As String

Name = UserNameTB.Value
Pass = PasswordTB.Value

Cells(1, 1).Select
For a = 1 To 20
If Name = ActiveCell.Value And Pass = ActiveCell.Offset(0
1).Value Then GoTo GroupCompare

MsgBox ("Wrong Password!")
Next a
Cells(1, 1).Select


GroupCompare:
If ActiveCell.Offset(0, 2) = "N" Then
Show TimesheetEntry
ElseIf ActiveCell.Offset(0, 2) = "A" Then
Show LoginOption

End If
End Sub
 
R

Rob van Gelder

Kenneth,

Private Sub OkBtn_Click()
Dim strUsername As String, strPassword As String
Dim i As Long, lngLastRow As Long, blnFound As Boolean

strUsername = UserNameTB.Value
strPassword = PasswordTB.Value

With ActiveSheet
lngLastRow = .Cells(Rows.Count, 1).End(xlUp).Row
blnFound = False
For i = 1 To lngLastRow
If strUsername = .Cells(i, 1).Value Then
If strPassword = .Cells(i, 2).Value Then
blnFound = True
Exit For
Else
MsgBox "Wrong Password!"
Exit For
End If
End If
Next

If blnFound Then
Select Case .Cells(i, 3).Value
Case "N": Show TimesheetEntry
Case "A": Show LoginOption
End Select
End If
End With
End Sub


Rob
 
M

maxifire

Hi Rob,

Good to hear from you. Will try out the code and keep you informed
Thanks once again! ;)


Regards,
Kennet
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top