I raised a query on Friday (here is the query) which works perfectly as per David Zemens instructions and BrakNicku guidance. Problem I have is that: one of the events I want to use is Enter. Unfortunately, within the class, I don't get the option for this event. Does anyone one know if there is a way to perhaps add this to the class or trigger an Enter event for the control somehow?
I've tried using most of the events available within the class but none of them behave the way I need them to. Just to give a quick background: I use Enter event to set help text for the field in focus. So everytime user enters a field, I have a help textbox that gets populated with help text
Unfortunately, I am unable to share the workbook but happy to answer any questions
Thanks in advance
So the approach I went with was: I already had Class Module that was trapping
Change
event (can be seen here). As i didnt have access toEnter
event in my class, I used theKeyUp
andMouseDown
events in this class to set help for each control. This way user can get to a field by clicking on it or tabbing to it: help is displayed for the selected controlHere another solution, (doesnot work on a MAC)
Open Notepad and copy code below and paste it in a new txt-file save it als CatchEvents.cls
In your VBA editor you import this File
In your Userform code you add:(when you have already an Initialize-event you combine those)
Now every Enter-event of any control will be catched, so you have to act accordingly. Every event on a Userform can be catched this way.
Let's say your userform (Userform1) looks like this
I am going to demonstrate the
Enter Event
for 2 controls.TextBox
andComboBox
.Ensure that you place the
CommandButton1
first on the userform. Or alternatively, set it'sTabIndex
to0
. This is so that the command button takes focus first when the userform loads and you can test theEntering
ofTextBox
andComboBox
.Paste this in a class module. My Class module name is
Class1
Paste this in the userform code area
Demo