Hooking column select (1 Viewer)

giedrius

Registered User.
Local time
Today, 09:52
Joined
Dec 14, 2003
Messages
80
Hello,

Is it really possible (and how) to get hold if a user clicked on a column title (selected the whole column) in Datasheet view on a form? I want to be able to reverse sort order of the marked column.
 

WayneRyan

AWF VIP
Local time
Today, 08:52
Joined
Nov 19, 2002
Messages
7,122
giedrius,

The form view toolbar has the A-Z and Z-A. You shouldn't have to do
anything.

Wayne
 

pono1

Registered User.
Local time
Today, 00:52
Joined
Jun 23, 2002
Messages
1,186
giedrius said:
Is it really possible (and how) to get hold if a user clicked on a column title (selected the whole column) in Datasheet view on a form? I want to be able to reverse sort order of the marked column.

I second Wayne's recommendation but to answer your question, yes, you can subclass a window in VBA starting with Access 2000. Sorry, no code sample handy, though. Also, if a listview control is available for use with Access (I'm not sure if it is, or not), they are easy to sort (just a few lines of code) when the user clicks on a column header. Most any VB book or forum would have an example...

Regards,
Tim
 

giedrius

Registered User.
Local time
Today, 09:52
Joined
Dec 14, 2003
Messages
80
pono1 said:
...you can subclass a window in VBA starting with Access 2000....

Not sure I understand what does it mean "to subclass". I am sorry, I am not very experienced in Access.

giedrius
 

pono1

Registered User.
Local time
Today, 00:52
Joined
Jun 23, 2002
Messages
1,186
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
 

giedrius

Registered User.
Local time
Today, 09:52
Joined
Dec 14, 2003
Messages
80
Tim

Thanks for your good explanation. It is a good starting point for deeper investigation into the subject. I really appreciate it.

Giedrius
 

giedrius

Registered User.
Local time
Today, 09:52
Joined
Dec 14, 2003
Messages
80
WayneRyan said:
The form view toolbar has the A-Z and Z-A. You shouldn't have to do
anything.

This is OK when you have a simple sort. In my case it is a sort on more than one column and I want to give user a simple way of just clicking on the title of the main sort column.

giedrius
 

Users who are viewing this thread

Top Bottom