Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting on a field in the form header

Status
Not open for further replies.

Larshg

Programmer
Mar 1, 2001
187
DK
I have a subform that consist of a table and in the form Header there are fields and I want to make it able to sort the tabel according to the field when I clik on it.

I know that you can do this by right clikking and the choosing desending or assending - but I want it for do it when i clik whit the left button, and then just sort it opposite of how it did it last time.
 
Hi Larshg,
This one is really sweet and I'm sure lots of folks would appreciate it:

Open up the VB module "behind" the form by finding the button on the toolbar that has a control tip text that says "code" (**Could someone tell me what that icon is supposed to be please?)

Place your sub form in design view. Paste this in right below the "Option Compare Database" or if you have it, just below "Option Explicit":

Dim ctl As Control, fSetting As Boolean
Private Sub SortMe()
on error Resume Next
Set ctl = Me.ActiveControl
DoCmd.RunCommand acCmdRemoveFilterSort
ctl.SetFocus
If fSetting = True Then
DoCmd.RunCommand acCmdSortAscending
fSetting = False
Else
DoCmd.RunCommand acCmdSortDescending
fSetting = True
End If
End Sub


Close the VB module.
Now on each of the fields that you might like to sort, find their On Double-click event. Select "event procedure", click "..." to open the module again and automatically label a sub, then add this:

SortMe

You'll have to keep doing this for each field. Once done close and save. Open your form and go to a column and double-click. Then double-click again. Good? Gord
ghubbell@total.net
 
P.S. Oh ya, I forgot to say: do this to the fields themselves, not the "Labels" for the fields which is probably what you have in the header...(not that it couldn't be done, just that this code wouldn't do it.) :) Gord
ghubbell@total.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top