Solved

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

Posted on 2012-04-08
16
524 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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!

 
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

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.

Question has a verified solution.

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

Mailbox Overload?
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

691 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