View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rob van Gelder[_4_] Rob van Gelder[_4_] is offline
external usenet poster
 
Posts: 1,236
Default 3 conditions if else statement.

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

"maxifire " wrote in message
...
Hi Guys,

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

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

In the if-else statement, I plan to code it in such a way that it will
scan through the spreadsheet looking for the username and once it
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 a
different menu between administrators and users.

The following code which I coded, unfortunately does not work due to
some reasons. :( Will be really grateful if someone could
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


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

End If
End Sub

---


---
Message posted from http://www.ExcelForum.com/