Treating Enter Keys as Tabs
Posted on 2001-06-13
My ex-DOS users insist on using either the Tab or Enter key to navigate from one field to another. No problem. I use KeyPreview, intercept the Enter keys and send a tab. It works fine, except for one sticky point:
When I do a data-check (on the LostFocus event of a control), I issue a MsgBox error message if the data doesn't pass muster. Then I SetFocus to the control with the bad data, and all ought to be well.
It is, unless the user responds to the MsgBox with an Enter key. Then focus goes to the control immediately after the one with the bad data. This doesn't happen, of course, when the user clicks on the OK of the MsgBox.
It seems clear that what's happening is that I'm setting the focus OK, but then the tab that I send when I see an Enter is doing what tabs always do, moves the focus to the next control.
What I want to do is to avoid issuing the tab when I see an Enter, if the user is responding to a MsgBox. The problem is, how do I detect that?
I tried this in my keyboard event Sub, just before Sending a tab when I see an Enter:
If TypeOf Screen.ActiveControl Is MsgBox Then
Since MsgBox is not a control, I didn't have much hope for this. It didn't work.
Does anyone have any ideas? It seems a simple problem, but I don't have a solution.