• Home
  • Forums
  • COMPUTER
  • 💻 Coding & Programming

Closed If else if statement error

  • Thread starter Thread starter Eyaa-
  • Start date Start date Mar 22, 2018
  • Tags Tags
    vba
Status
Not open for further replies.
E

Eyaa-

Honorary Poster
  • Mar 22, 2018
  • #1
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
 
F

Funyarinpa

Forum Guru
  • Mar 22, 2018
  • #2
wala yatang space ang -ElseIf- sa VBA...
 
TS
TS
E

Eyaa-

Honorary Poster
  • Mar 22, 2018
  • #3
Touka Koukan said:
wala yatang space ang -ElseIf- sa VBA...
Click to expand...
nakuha mo pre salamat hahaha. yung sa Do Until na Statement naman ang may problema
 
F

Funyarinpa

Forum Guru
  • Mar 22, 2018
  • #4
Eyaa- said:
ung sa Do Until na Statement naman ang may problema
Click to expand...
yung -IsEmpty- function wala pong space
 
TS
TS
E

Eyaa-

Honorary Poster
  • Mar 22, 2018
  • #5
Touka Koukan said:
yung -IsEmpty- function wala pong space
Click to expand...
salamat madami bro
 
F

Funyarinpa

Forum Guru
  • Mar 22, 2018
  • #6
^ same lang din po
yung mga properties dapat walang space [BorderColor], [BackColor], [ForeColor]
 
TS
TS
E

Eyaa-

Honorary Poster
  • Mar 22, 2018
  • #7
Touka Koukan said:
^ same lang din po
yung mga properties dapat walang space [BorderColor], [BackColor], [ForeColor]
Click to expand...
okay na bro na sagot ko na
 
Status
Not open for further replies.

Popular Tags

android api app arduino bot c c++ capstone capstone project code coding coding and programming course css database developer development free help how how to html in java javascript language laravel mag mysql need need help patulong php program programmer programming programming language project python question react sql system thesis tutorial udemy using visual basic web with
Share:
Facebook X Bluesky LinkedIn Reddit Pinterest Tumblr WhatsApp Email Share Link
  • Home
  • Forums
  • COMPUTER
  • 💻 Coding & Programming
  • View Non-AMP Version
  • Contact us
  • Terms and rules
  • Privacy policy
  • Help
  • Home
Menu
Log in

Register

  • Home
    • Shoutbox
    • Miscellaneous
    • Mobile Network
    • Internet
    • Mobile Phone
    • Media
    • Computer
    • Game
    • Lounge
  • Forums
    • New topics New questions Popular today Popular this month New posts
  • What's new
    • Featured content
    • New posts
    • New media
    • New media comments
    • Latest activity
  • Media
    • New media
    • New comments
    • Search media
  • Search
    • Advanced search
X

Privacy & Transparency

We use cookies and similar technologies for the following purposes:

  • Personalized ads and content
  • Content measurement and audience insights

Do you accept cookies and these technologies?

X

Privacy & Transparency

We use cookies and similar technologies for the following purposes:

  • Personalized ads and content
  • Content measurement and audience insights

Do you accept cookies and these technologies?