cannot input text in the textbox
I cannot insert any input into my textbox. Every time I insert one text or number from keyboard, I got this messagebox MsgBox "Please input valid password", vbCritical, "Warning". So How I can input full password into my textbox?
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii ' This case statment check that no text can be entered.
Case vbKeyDelete ' Delete Key
Case vbKeyBack 'Baskspace key
Case vbKeyReturn
Case Else
Dim usrnm As String
usrnm = TextBox1.Text
adoRS.Close
adoRS.Open "SELECT * FROM pass WHERE password='" & usrnm & "';", adoConn, adOpenStatic, adLockOptimistic
If adoRS.Fields("Password").Value = TextBox1.Text And adoRS.Fields("username").Value = "Pengurus" Then
pass = True
'if password valid, success
Unload Me
frmMain.Show
Else
'If password invalid
intCounter = intCounter + 1
If intCounter = 4 Then
MsgBox "You have insert invalid password more then 3", vbCritical, "Warning"
intCounter = 0
Unload Me
Application.Shutdown
Else
MsgBox "Please input valid password", vbCritical, "Warning"
TextBox1.SetFocus
TextBox1.Text = ""
End If
End If
Re: cannot input text in the textbox
That's because you are telling it to check it everytime you enter a character (equivalent to pressing a key) in the textbox...
Private Sub Text1_KeyPress(KeyAscii As Integer) <======
you need to use a different approach. Since you are already comparing the password here
If adoRS.Fields("Password").Value = TextBox1.Text And ......
Then does it really matter to restrict the input in the textbox?
Re: cannot input text in the textbox
Try something like
Code:
Private Sub Text1_LostFocus()
Dim usrnm As String
usrnm = TextBox1.Text
adoRS.Close
adoRS.Open "SELECT * FROM pass WHERE password='" & usrnm & "';", adoConn, adOpenStatic, adLockOptimistic
If adoRS.Fields("Password").Value = TextBox1.Text And adoRS.Fields("username").Value = "Pengurus" Then
pass = True
'if password valid, success
Unload Me
frmMain.Show
Else
'If password invalid
intCounter = intCounter + 1
If intCounter = 4 Then
MsgBox "You have insert invalid password more then 3", vbCritical, "Warning"
intCounter = 0
Unload Me
Application.Shutdown
Else
MsgBox "Please input valid password", vbCritical, "Warning"
TextBox1.SetFocus
TextBox1.Text = ""
End If
End If
End Sub