Solved

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

Posted on 2012-04-08
16
520 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
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.

 
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
 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

860 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