PC Review


Reply
Thread Tools Rate Thread

Control to use for sorting by column in continuous form

 
 
Brian
Guest
Posts: n/a
 
      20th Oct 2008
Does anybody have a suggestion for how, on a continuous form, to emulate the
type of column-based sorting such as exists, for example, in Outlook? I have
column labels in the form header and columnized data in the detail below the
headers. I want to allow the user to click on the header and get some sort of
indication of how the form is sorted.

I have no problem with the VBA to rewrite the form's record source & requery
with the ORDER BY clause(s), but I don't know what kind of control to embed
in the header such that it is a small Up Arrow when sorting ASC and Down
Arrow when sorting DESC and changes when the user clicks it. I could replace
the column header with a button, but I do not know how to combinine the text
(e.g. Customer)& graphic (up/down arrow) on the button. Even if I could, the
stock up & down button graphics are so large that they look out of place with
an eight-point font in the header.
 
Reply With Quote
 
 
 
 
John Spencer
Guest
Posts: n/a
 
      20th Oct 2008
Here is a bit of code that I use. I put the sub into a vba module and
then call it from the click event of the label.
sReorder Me.LabelControlName

using Me.LabelControlName lets this work in subforms and forms.


Public Sub sReorder(cntlLabel As Control)
'Reorder the displayed records on a form or subform when a label/control
'is clicked
'Uses the tag property of the label/control to decide which field is
'involved
'and to maintain the caption value of the label/control
'Tag should contain three items separated by semi-colons.
'Standard Label Tag would be
' Caption;Phrase"OrderBy";FieldName to Order by
'Example Tag: User Id;OrderBy;UserIdentifier


Dim cntlAny As Control
Dim arVar As Variant
Dim objParent As Variant 'form or subform.form
Dim strUP As String
Dim strDown As String

'With unicode fonts
strUP = ChrW(9650) 'Works with Arial to show solid UP triangle
strDown = ChrW(9660) 'Works with Arial to show solid Down triangle

'With non-unicode font uncomment the following lines
'strUP = "^"
'strDown = "/"

On Error GoTo sReorder_Error

Set objParent = cntlLabel.Parent

'If no records then don't bother to set sort
If objParent.RecordsetClone.RecordCount > 0 Then
arVar = Split(cntlLabel.Tag, ";", -1, 0) 'Get tag components

'Reset all relevant labels to default appearance
DoCmd.Echo False
For Each cntlAny In objParent.Controls
With cntlAny
If .Tag Like "*OrderBy*" Then
.Caption = Left(.Tag, InStr(1, .Tag, ";") - 1)
End If
End With
Next cntlAny

If objParent.OrderByOn = False Then
'Records were not sorted
objParent.OrderBy = arVar(2)
cntlLabel.Caption = arVar(0) & strUP

ElseIf objParent.OrderBy = arVar(2) Then
'Records were sorted by this field in Ascending order
objParent.OrderBy = arVar(2) & " DESC"
cntlLabel.Caption = arVar(0) & strDown

ElseIf objParent.OrderBy = arVar(2) & " DESC" Then
'Records were sorted by this field in Descending order
objParent.OrderBy = arVar(2)
cntlLabel.Caption = arVar(0) & strUP

Else
'Records were sorted by some other field
objParent.OrderBy = arVar(2)
cntlLabel.Caption = arVar(0) & strUP
End If

objParent.OrderByOn = True
DoCmd.RunCommand acCmdSelectRecord
DoCmd.Echo True
End If 'no records

EXIT_sReorder:
Exit Sub

sReorder_Error:
DoCmd.Echo True
MsgBox Err.Number & ": " & Err.Description, , objParent.Name & ":
sReorder"

End Sub

'Keywords: Sort Fields, Sort records, sort columns

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


Brian wrote:
> Does anybody have a suggestion for how, on a continuous form, to emulate the
> type of column-based sorting such as exists, for example, in Outlook? I have
> column labels in the form header and columnized data in the detail below the
> headers. I want to allow the user to click on the header and get some sort of
> indication of how the form is sorted.
>
> I have no problem with the VBA to rewrite the form's record source & requery
> with the ORDER BY clause(s), but I don't know what kind of control to embed
> in the header such that it is a small Up Arrow when sorting ASC and Down
> Arrow when sorting DESC and changes when the user clicks it. I could replace
> the column header with a button, but I do not know how to combinine the text
> (e.g. Customer)& graphic (up/down arrow) on the button. Even if I could, the
> stock up & down button graphics are so large that they look out of place with
> an eight-point font in the header.

 
Reply With Quote
 
Brian
Guest
Posts: n/a
 
      20th Oct 2008
Bingo!

The ChrW(9650) did the trick. After my post, I had gotten as far as trying
to insert Chr(30) & Chr(31); however, those both display as squares/unknowns
in labels. I was not aware of the more complete characters set available with
the ChrW function and so was beating my head against the wall trying to
insert buttons, etc.

Thank you so much.

"John Spencer" wrote:

> Here is a bit of code that I use. I put the sub into a vba module and
> then call it from the click event of the label.
> sReorder Me.LabelControlName
>
> using Me.LabelControlName lets this work in subforms and forms.
>
>
> Public Sub sReorder(cntlLabel As Control)
> 'Reorder the displayed records on a form or subform when a label/control
> 'is clicked
> 'Uses the tag property of the label/control to decide which field is
> 'involved
> 'and to maintain the caption value of the label/control
> 'Tag should contain three items separated by semi-colons.
> 'Standard Label Tag would be
> ' Caption;Phrase"OrderBy";FieldName to Order by
> 'Example Tag: User Id;OrderBy;UserIdentifier
>
>
> Dim cntlAny As Control
> Dim arVar As Variant
> Dim objParent As Variant 'form or subform.form
> Dim strUP As String
> Dim strDown As String
>
> 'With unicode fonts
> strUP = ChrW(9650) 'Works with Arial to show solid UP triangle
> strDown = ChrW(9660) 'Works with Arial to show solid Down triangle
>
> 'With non-unicode font uncomment the following lines
> 'strUP = "^"
> 'strDown = "/"
>
> On Error GoTo sReorder_Error
>
> Set objParent = cntlLabel.Parent
>
> 'If no records then don't bother to set sort
> If objParent.RecordsetClone.RecordCount > 0 Then
> arVar = Split(cntlLabel.Tag, ";", -1, 0) 'Get tag components
>
> 'Reset all relevant labels to default appearance
> DoCmd.Echo False
> For Each cntlAny In objParent.Controls
> With cntlAny
> If .Tag Like "*OrderBy*" Then
> .Caption = Left(.Tag, InStr(1, .Tag, ";") - 1)
> End If
> End With
> Next cntlAny
>
> If objParent.OrderByOn = False Then
> 'Records were not sorted
> objParent.OrderBy = arVar(2)
> cntlLabel.Caption = arVar(0) & strUP
>
> ElseIf objParent.OrderBy = arVar(2) Then
> 'Records were sorted by this field in Ascending order
> objParent.OrderBy = arVar(2) & " DESC"
> cntlLabel.Caption = arVar(0) & strDown
>
> ElseIf objParent.OrderBy = arVar(2) & " DESC" Then
> 'Records were sorted by this field in Descending order
> objParent.OrderBy = arVar(2)
> cntlLabel.Caption = arVar(0) & strUP
>
> Else
> 'Records were sorted by some other field
> objParent.OrderBy = arVar(2)
> cntlLabel.Caption = arVar(0) & strUP
> End If
>
> objParent.OrderByOn = True
> DoCmd.RunCommand acCmdSelectRecord
> DoCmd.Echo True
> End If 'no records
>
> EXIT_sReorder:
> Exit Sub
>
> sReorder_Error:
> DoCmd.Echo True
> MsgBox Err.Number & ": " & Err.Description, , objParent.Name & ":
> sReorder"
>
> End Sub
>
> 'Keywords: Sort Fields, Sort records, sort columns
>
> '====================================================
> John Spencer
> Access MVP 2002-2005, 2007
> Center for Health Program Development and Management
> University of Maryland Baltimore County
> '====================================================
>
>
> Brian wrote:
> > Does anybody have a suggestion for how, on a continuous form, to emulate the
> > type of column-based sorting such as exists, for example, in Outlook? I have
> > column labels in the form header and columnized data in the detail below the
> > headers. I want to allow the user to click on the header and get some sort of
> > indication of how the form is sorted.
> >
> > I have no problem with the VBA to rewrite the form's record source & requery
> > with the ORDER BY clause(s), but I don't know what kind of control to embed
> > in the header such that it is a small Up Arrow when sorting ASC and Down
> > Arrow when sorting DESC and changes when the user clicks it. I could replace
> > the column header with a button, but I do not know how to combinine the text
> > (e.g. Customer)& graphic (up/down arrow) on the button. Even if I could, the
> > stock up & down button graphics are so large that they look out of place with
> > an eight-point font in the header.

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
column width in continuous form Fev Microsoft Access Forms 1 7th Sep 2011 03:34 PM
Freezing a column on continuous form John Microsoft Access 3 9th May 2009 09:09 PM
Is there a way to do Sorting and Grouping on a continuous form, similar to a report? M Skabialka Microsoft Access Forms 6 21st Mar 2008 04:20 PM
More than 1 column in continuous form? =?Utf-8?B?TmluaWVs?= Microsoft Access 13 3rd Oct 2006 08:14 PM
Column in Continuous Form Simon Microsoft Access Forms 0 26th Aug 2003 04:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:54 AM.