I have a login form to my database done in Access 2010 and using VBA code. I want to be able to press Enter on txtboxPassword and automatically execute btnLogin_Click event. I tried this:
Private Sub txtboxPassword_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then btnLogin_Click End If End Sub What I get is a self-made error saying Password is incorrect. If I debug I see that actually txtPassword is null, but I just typed the text in it!
However If I click the Login button with the mouse it works perfect. Why does vba behave like that? How can I do it to make it work?
NOTE I also tried with:
- KeyPress: after I press Enter the focus goes to
btnLogin(maybe also because the tab order is like that), but thebtnLogin_Clickevent is not executed. - KeyUp: same like KeyPress.
txtPasswordis null? Textboxes have aTextproperty. But that one is usually an empty string but notnull.null