Greg Truby
MrExcel MVP
- Joined
- Jun 19, 2002
- Messages
- 10,025
Tried searching the archives to no avail. Here's the deal:
Userform, lots of controls. Have a button that when clicked, will make a call to terminal emulation software and pull back information and drop that information into textbox controls. The series of textboxes varies depending on which row of controls has focus (twenty-four rows of controls visible at a time). The button works fine when clicked because TakeFocusOnClick is set to FALSE. However, if I assign an accelerator key to the button, the accelerator sets the focus to the button and now I don't know which row of textboxes should be the target of the information gathered by the button's subroutine because they no longer have focus.
My thought was to create a global object variable to hold a pointer to the control that had focus prior to the button taking focus.
The controls that are in the same row as the target textboxes and hence can have focus prior to the button's method firing can be a mix of ComboBoxes, Textboxes or RefEdits. So trying to dump all of these into an array + class module type of solution is a not an attractive solution (if it's even possible).
So what I'm thinking is to try and trap on KeyDown events (to trap tabbing from control to control) and on MouseDown events, but at a form level to see if I can set up a way to track using a global object variable like I mentioned above. But when I put simple tests in the UserForm's code like:
they are not firing. So I'm assuming that the KeyDown and MouseDown events are getting handled at a lower level and not bubbling up to the parents (Page|MultiPage|UserForm). So now we're to the title of this thread and my question: Is there some type of property setting or something I can do to get the KeyDown and MouseDown events to bubble up the chain of containers and hit the form's event handlers?
Another idea that occurs to me is to use a class module and try to assign the userform to that WithEvents. Is that a possibility?
Or if anyone has a brilliant idea on another way to attack this problem, I'm open to suggestions.
Userform, lots of controls. Have a button that when clicked, will make a call to terminal emulation software and pull back information and drop that information into textbox controls. The series of textboxes varies depending on which row of controls has focus (twenty-four rows of controls visible at a time). The button works fine when clicked because TakeFocusOnClick is set to FALSE. However, if I assign an accelerator key to the button, the accelerator sets the focus to the button and now I don't know which row of textboxes should be the target of the information gathered by the button's subroutine because they no longer have focus.
My thought was to create a global object variable to hold a pointer to the control that had focus prior to the button taking focus.
The controls that are in the same row as the target textboxes and hence can have focus prior to the button's method firing can be a mix of ComboBoxes, Textboxes or RefEdits. So trying to dump all of these into an array + class module type of solution is a not an attractive solution (if it's even possible).
So what I'm thinking is to try and trap on KeyDown events (to trap tabbing from control to control) and on MouseDown events, but at a form level to see if I can set up a way to track using a global object variable like I mentioned above. But when I put simple tests in the UserForm's code like:
Code:
Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
MsgBox "Form Keydown"
End Sub
Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
MsgBox "Form MouseDown"
End Sub
they are not firing. So I'm assuming that the KeyDown and MouseDown events are getting handled at a lower level and not bubbling up to the parents (Page|MultiPage|UserForm). So now we're to the title of this thread and my question: Is there some type of property setting or something I can do to get the KeyDown and MouseDown events to bubble up the chain of containers and hit the form's event handlers?
Another idea that occurs to me is to use a class module and try to assign the userform to that WithEvents. Is that a possibility?
Or if anyone has a brilliant idea on another way to attack this problem, I'm open to suggestions.