I have a login form to my database, made in Access 2010, and using VBA code. I want to be able to press Enter on txtboxPassword and automatically execute the 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 makeshift error as the password is incorrect. If I'm debugging, I see that txtPassword is actually null , but I just typed in it!
However, if I click the Login button with the mouse, it works perfectly. Why does VBA behave like this? How can I make it work?
NOTE I also tried:
- KeyPress: after pressing Enter, the focus switches to
btnLogin (possibly also because the tab order is similar to this), but the btnLogin_Click event btnLogin_Click not executed. - KeyUp: same as KeyPress.
vba ms-access ms-access-2010
EricPb
source share