giedrius said:
Not sure I understand what does it mean "to subclass". I am sorry, I am not very experienced in Access.
Giedrius,
Background: When you're working with Access (or any other program) on your computer, you are, in fact, not working directly with Access. Instead, when you type a character or click the screen, Windows grabs that "keystroke" or "click" and delivers it to Access on your behalf. Access only knows you want to do something because Windows tells it what you want to do. Windows -- the operating system -- is in charge. It is the conductor and messenger of all the activity on the system.
When you subclass a window, which is often described as "hooking into the operating system" -- you used the term "hook" in the subject title of this thread so I thought you were asking specifically about subclassing -- your code intercepts operating system messages before they are delivered to a form or a control. Usually, depending on the specific message, your code then reacts one way or another.
The unpleasant aspect of subclassing a window is that it involves a lot of coding (the nice thing about Access is that so much can be done with so little code) and, too, it is relatively treacherous -- one small mistake and the application freezes or snaps shut, regardless of error handling. Because of the code and relative risk, subclassing is usually a last resort to accomplish a particular task; and it is a technique more commonly used by Visual Basic programmers rather than Access developers. VB 6'ers, for example, have no native means to put an icon on a pulldown menu. If they want this feature in their application, they must subclass a window, intercepting "menu messages" sent from Windows to the form, "adding icons" to these messages before forwarding them on to the form. (Or they can buy a control that does it all for them -- the control will do the subclassing behind the scenes.)
What do you use in your code to subclass? APIs and something called the AddressOf keyword. Again, not recommended but if you're still interested, look up SetWindowLong at
www.AllAPI.net and AddressOf at msdn.com. Warning: it may take some time to become comfortable with this if it's new to you. Another thing: subclassing will, in time, drift away. It is, for example, not as important as it once was for Visual Basic programmers who upgraded to VB.Net, which allows them to do more things than earlier VB versions.
Regards,
Tim