[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 535
  • Last Modified:

How to sort a column in vbAccelerator DataGrid used in Outlook 2007 VBA

We have vbAccelerator DataGrid being used in our Outlook 2007 via VBA.

We are trying to make the Grid be Sorted by the column the user clicks on.  

What is the best method to go about it?
0
rayluvs
Asked:
rayluvs
  • 8
  • 8
1 Solution
 
Chris Raisin(Retired Analyst/Programmer)Commented:
Ok...I'm awake still!  :-)


Sorting is always performed via the SortObject

Do you want to sort on ONE column only?

We could perhaps RIGHT click to set the column to be sorted then LEFT click to have it toggel between ASCENDING and then DESCENDING.

What would you like?

Cheers
Chris
0
 
rayluvsAuthor Commented:
Hey!!! We though you would be counting sheeps!!

We need that when the user clicks on 'Tasks', the current grid would sort A-Z it's contents by 'Tasks'.  If the user clicks again, would revert the sort Z-A.
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
OK...working on it (sleep-typing...not sleep-walking)

Stand By...

Chris
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Chris Raisin(Retired Analyst/Programmer)Commented:
Do you want it to be ONLY for that column, or for any column the user picks?

Cheers
Chris
0
 
rayluvsAuthor Commented:
any column
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
OK - Here it is!  :-)

This must be placed in the code that resides in the UserForm.

There is provision to tweak the code for columns that are sorted by date or icon rather than text, (The default is text)

It is only set for one column at a time at the moment so if you want to "subsort" you can (up to three columns deep) but I will have to work on that code when I finally get up (it is now 5.50am). (You might want to sort on "Subject within Type within Project" perhaps.)
That would be a challenge but I would be happy to try it for you.

Cheers
Chris

Public Sub gridItemsFound_ColumnClick(ByVal lCol As Long)
Dim sTag As String
Dim i As Long

With gridItemsFound.SortObject
  .Clear
  .SortColumn(1) = lCol
  sTag = gridItemsFound.ColumnTag(lCol)
  If (sTag = "") Then
    sTag = "DESC"
    .SortOrder(1) = CCLOrderAscending
  Else
    sTag = ""
    .SortOrder(1) = CCLOrderDescending
  End If
  gridItemsFound.ColumnTag(lCol) = sTag
  Select Case gridItemsFound.ColumnKey(lCol)
    Case "", ""
      ' sort by icon:
      .SortType(1) = CCLSortIcon
    Case ""
      'date columns
      ' sort by date:
      .SortType(1) = CCLSortDate
    Case Else
      ' sort by text:
      .SortType(1) = CCLSortString
  End Select
End With
UserForm1.MousePointer = fmMousePointerHourGlass
gridItemsFound.Sort
UserForm1.MousePointer = fmMousePointerDefault
End Sub

Open in new window

0
 
rayluvsAuthor Commented:
Ok will check...
0
 
rayluvsAuthor Commented:
Worked excellently!
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
Would you like multiple columns?

Cheers
Chris  (snore!....snore!....zzzzzz....zzzzz)
0
 
rayluvsAuthor Commented:
By multiple columns, what do you mean specifically?
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
Well, when you click on (say) "Projects" then the order could be Tasks sorted alphabetically (does not make much sense) within project, and then "Subject" within each Task.

I think in this exercise it does not make much sense to have multiple sorts, unless you perhaps introduce a "Priority" field such as "1" (Urgent), "2" (high),"3" Medium, "4" (Low),  "5" (Very Low) and then the tasks could be sorted on their priority within a project.

Anyway, I will look at how the sorting works and even if you do not use it, at least I will have that info should others need it at any time.

I think though that since it is quite involved, it should be asked as a new question (should you feel you would like it). I have basically answered this question already.

Did you look at the final code I left in the other question? I think you will find it very beneficial should the user want to actually view the email "double-clicked" upon in the grid.


Cheers
Chris


Cheers
Chris
0
 
rayluvsAuthor Commented:
I talked to my boss and the current sorting already provided is enough.

We have been running the apps and a series of question surfaced, but will open a new question for that.  This question on sorting has been answered.

Thanx
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
OK - I will keep my eyes peeled :-)

Cheers
Chris
0
 
rayluvsAuthor Commented:
We placed a couple of question regarding sorting and headers.  Please advice
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
Have done and am responding.

I have set up a special filter so that whenever you submit a new question, I receive an email advising me of it - EE works pretty efficiently, eh?  :-)

Cheers
Chris
0
 
rayluvsAuthor Commented:
Yes it does!  That is why I stick to EE!
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

  • 8
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now