What's new

Closed If else if statement error

Status
Not open for further replies.

Eyaa-

Eternal Poster
Joined
Jul 22, 2016
Posts
607
Reaction
373
Points
279
Hello guys. I'm trying to work an OLD PLanguage which is the VBA on Excel not familiar dahil medyo iba ang mga Functions Compare sa PL na Visual Basic.

Let's Start!

Trying to make a Log in Form Validating on the Current Sheet.
Error ko yung Condition na:
IF ELSE IF Statement Cmd_Submit_Click () which is the Button.
NOTE: yung red line is yung error ko na statement na nag error message is MUST BE FIRST STATEMENT ON THE LINE. yung yellow line sa code naman ang error ko SYNTAX ERROR.

baka meron pwede maka tulong sakin dyan. Salamat

Here's my Code.

Private Sub UserForm_Click()
Public Username As String
Public Password As String
Public i As Integer
Public j As Integer
Public u As String
Public p As String

Sub clear()
TextBox1.Value = ""
TextBox2.Value = ""
End Sub

Private Sub Cmd_Submit_Click()
Application.ScreenUpdating = False
If Trim(TextBox1.Text) = "" And Trim(TextBox2.Text) = "" Then
MsgBox "Enter username and password.", vbOKOnly
Else If Trim (TextBox1.Text) = "" Then
MsgBox "Enter the username ", vbOKOnly
Else If Trim(TextBox2.Text) = "" Then
MsgBox "Enter the Password ", vbOKOnly
Else
Username = Trim(TextBox1.Text)
Password = Trim(TextBox2.Text)
i = 1
Do While Cells(1, 1).Value <> ""
j = 1
u = Cells(i, j).Value
j = j + 1
p = Cells(i, j).Value
If Username = u And Password = p And Cells(i, 3).Value = "fail" Then
MsgBox "Your Account temporarily locked", vbCritical
Exit Do
Else If Username = u And Password = p Then
Call clear
UserForm1.Hide
UserForm2.Label1.Caption = u
UserForm2.Label1.ForeColor = &H8000000D
UserForm2.Show
Exit Do
Else If Username <> u And Password = p Then
MsgBox "Username not matched", vbCritical + vbOKCancel
Exit Do
Else If Username = u And Password <> p Then
If Cells(i, 3).Value = "fail" Then
MsgBox "Your account is blocked", vbCritical + vbOKCancel
Exit Do
Else If Cells (i, 4).Value < 2 Then
MsgBox "Invalid password", vbCritical
Cells(i, 4).Value = Cells(i, 4) + 1
Exit Do
Else
Cells(i, 4).Value = Cells(i, 4) + 1
Cells(i, 3).Value = "fail"
Cells(i, 2).Interior.ColorIndex = 3
Exit Do
End If
Else
i = i + 1
End If
Loop
End If
Application.ScreenUpdating = True
End Sub


Private Sub TextBox1_Enter()
With TextBox1
.Back Color = &H8000000E
.Fore Color = &H80000001
.Border Color = &H8000000D
End With
TextBox1.Text = ""
End Sub
Private Sub TextBox1_AfterUpdate()
If TextBox1.Value = "" Then
TextBox1.BorderColor = RGB(255, 102, 0)
End If
i = 1
Do Until Is Empty (Cells (i, 1).Value)
If TextBox1.Value = Cells(i, 1).Value Then
With TextBox1
.Border Color = RGB(186, 214, 150)
.Back Color = RGB(216, 241, 211)
.Fore Color = RGB(81, 99, 51)
End With
End If
i = i + 1
Loop
End Sub
Private Sub TextBox2_Enter()
With TextBox2
.Back Color = &H8000000E
.Fore Color = &H80000001
.Border Color = &H8000000D
End With
TextBox2.Text = ""
End Sub
Private Sub TextBox2_AfterUpdate()
i = 1
Username = TextBox1.Value
Password = TextBox2.Value
If TextBox2.Text = "" Then
TextBox2.BorderColor = RGB(255, 102, 0)
End If
Do Until Is Empty (Cells (i, 1).Value)
j = 1
u = Cells(i, j).Value
j = j + 1
p = Cells(i, j).Value
If Username = u And Password = p Then
With TextBox2
.Border Color = RGB(186, 214, 150)
.Back Color = RGB(216, 241, 211)
.Fore Color = RGB(81, 99, 51)
End With
Exit Do
Else If Username = u and Password <> p Then
TextBox2.BorderColor = RGB(255, 102, 0)
Exit Do
Else
i = i + 1
End If
Loop
End Sub
Sub settings()
With UserForm1
TextBox1.ForeColor = &H8000000C
TextBox2.ForeColor = &H8000000C
TextBox1.BackColor = &H80000004
TextBox2.BackColor = &H80000004
TextBox1.Text = "Username"
TextBox2.Text = "Password"
TextBox1.BorderColor = RGB(0, 191, 255)
TextBox2.BorderColor = RGB(0, 191, 255)
CommandButton1.SetFocus
End With
End Sub
Private Sub UserForm1_Initialize()
Call settings
End Sub
 
Status
Not open for further replies.
Back
Top