[RESOLVED] help keypress "VbkeyReturn"
im making a simple login form,
i want to use the keypress,
when i enter my username and password and hit the enterkey,
the form2 will appear and also the msgbox if the username and password,is wrong.this what i have,but is not working,pls help what is worng or what should i do...tanx
Code:
Private Sub Command1_Click()
If Text1.Text = "aaa" And Text2.Text = "111" Then
Form2.Show
Unload Me
Else
MsgBox "wrong"
Text1.SetFocus
Text1.Text = ""
Text2.Text = ""
End If
Form1.KeyPreview = True
End Sub
Private Sub Command1_KeyPress(KeyAscii As Integer)
Select Case KeyCode
Case vbKey13
Call Command1_Click
End Select
End Sub
Re: help keypress "VbkeyReturn"
Welcome to the Forums.
Set the KeyPreview property of your Form1 from your property grid window instead of at runtime in the command1_click event, it will be too late to receive the prop change at that time.
Re: help keypress "VbkeyReturn"
u can set the command button default property = true, then if u press enter, command_click event wil be executed.
Re: help keypress "VbkeyReturn"
Quote:
Originally Posted by jhamez
Private Sub Command1_KeyPress(KeyAscii As Integer)
Select Case KeyCode
Case vbKey13
Call Command1_Click
End Select
End Sub[/code]
There is no KeyCode in a KeyPress event.
Code:
Private Sub Command1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
Command1.Value = True
End If
End Sub
Re: help keypress "VbkeyReturn"
Re: help keypress "VbkeyReturn"
We are glad to have helped.
Ps, dontforget to mark your thread as Resolved from the Thread Tools so others will know your question has been answered. ;)