Solved

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

Posted on 2012-04-08
16
516 Views
Last Modified: 2012-04-09
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
Comment
Question by:rayluvs
  • 8
  • 8
16 Comments
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 37821560
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
 

Author Comment

by:rayluvs
ID: 37821575
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
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 37821625
OK...working on it (sleep-typing...not sleep-walking)

Stand By...

Chris
0
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 37821647
Do you want it to be ONLY for that column, or for any column the user picks?

Cheers
Chris
0
 

Author Comment

by:rayluvs
ID: 37821649
any column
0
 
LVL 13

Accepted Solution

by:
Chris Raisin earned 500 total points
ID: 37821703
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
 

Author Comment

by:rayluvs
ID: 37821705
Ok will check...
0
 

Author Comment

by:rayluvs
ID: 37821711
Worked excellently!
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 13

Expert Comment

by:Chris Raisin
ID: 37821712
Would you like multiple columns?

Cheers
Chris  (snore!....snore!....zzzzzz....zzzzz)
0
 

Author Comment

by:rayluvs
ID: 37821716
By multiple columns, what do you mean specifically?
0
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 37822289
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
 

Author Comment

by:rayluvs
ID: 37822297
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
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 37822315
OK - I will keep my eyes peeled :-)

Cheers
Chris
0
 

Author Comment

by:rayluvs
ID: 37825319
We placed a couple of question regarding sorting and headers.  Please advice
0
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 37826038
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
 

Author Comment

by:rayluvs
ID: 37826061
Yes it does!  That is why I stick to EE!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Create high volume marketing opportunities using email signatures with these top 10 DOs and DON'Ts of email signature marketing.
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now