Are the textboxes bound? Do you have any code behind the text boxes'
KeyPress event that you didn't show here? I ask because you said it
throws
an invalid password when you press enter. The LostFocus event won't fire
until that control loses focus (who'd a thunk) when another control gets
focus.
If you wanted to, you can turn the enter key into a forward tab by
specifying which control to set focus to when the enter key is detected in
the textboxes' respective KeyPress events. Something like...
Private Sub txtUserName_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0 ' bye bye beep
txtPassword.SetFocus
End If
End Sub
Private Sub txtPassword_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0 ' bye bye beep
cmdOK.SetFocus
End If
End Sub
Or to simplify it, you can just do this in each KeyPress event...
If KeyAscii = 13 Then
KeyAscii = 0 ' bye bye beep
SendKeys "{TAB}"
End If
"Randi" <RSaddler@[EMAIL PROTECTED]
> wrote in message
news:R9TCb.11784$JW3.8837@[EMAIL PROTECTED]
> Hi All,
> I have a problem on a username password login form. I use:
> txtPassword.Text = StrConv(txtPassword.Text, vbProperCase) to validate
the
> proper case when someone enters their name and password. It work when
you
> use the button to continue, but if you hit enter on your keyboard the
event
> apparently doesnt lose focus and it says you entered the wrong password.
Is
> there an easy fix for this. I pointed out the problem code below. Any
help
> would be appreciated.
>
> Thanks,
> Kelsey
>
> Option Explicit
>
> Public LoginSucceeded As Boolean
>
> Private Sub cmdCancel_Click()
> 'set the global var to false
> 'to denote a failed login
> LoginSucceeded = False
> Unload Me
> End Sub
>
> Private Sub cmdOK_Click()
> Dim db As Database
> Dim rs As DAO.Recordset
>
> Set db = OpenDatabase(App.Path & "\testlogin.mdb")
> Set rs = db.OpenRecordset("login")
>
> Do While Not rs.EOF
> If txtUserName.Text = "Guest" And txtPassword.Text = "Guest"
Then
> Guest.Show
> Exit Sub
> End If
> If rs.Fields("username") = (txtUserName.Text) And _
> rs.Fields("password") = (txtPassword.Text) Then
> Form1.Show
> Unload Me
> Exit Sub
> Else
> rs.MoveNext
> End If
> Loop
> txtPassword.Text = ""
> MsgBox "Incorrect Password!", vbCritical
> End Sub
> Private Sub txtPassword_LostFocus() <--------Here
> txtPassword.Text = StrConv(txtPassword.Text, vbProperCase)
> End Sub
>
> Private Sub txtUserName_LostFocus()
> txtUserName.Text = StrConv(txtUserName.Text, vbProperCase)
> End Sub
>
>
> Private Sub frmLogin_Load()
> Data1.DatabaseName = (App.Path & "\testlogin.mdb")
> Data1.RecordSource = "login"
> End Sub
>
>


|