• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1506
  • Last Modified:

Programmatically sort the objects in the Navigation Pane in Access 2010

In Microsoft Access 2010, I would like to be able to programmatically sort the objects in the Navigation Pane, but I have not been able to find the correct syntax to use.  

To manually sort, the user needs to right click the Navigation Pane header and select select Sort By, then select the field they want to sort their objects by.  But if you want to sort descending, the user needs to right-click again, select Sort By,  and then select Descending.  I want to create a macro, or use some VBA that I can associate with a button, so I can sort descending by last modified date with one click, rather than two right-clicks and four menu selections.  I do this sort all day, always looking for the most recent queries I have been working on.
0
upsfa
Asked:
upsfa
  • 5
  • 5
1 Solution
 
Jeffrey CoachmanCommented:
Not sure if I have ever seen this done (even in Access 2003 and older)

So you are giving your users complete and direct access to all Database objects instead of controlling this through forms...?


You can certainly create your own sort form quite easily.

Take the form from here and drop it into your database
(I am sure you will be able to easliy adapt it for different sort field options)
Database41.mdb
0
 
upsfaAuthor Commented:
Thanks, not what I'm looking for.   I already have a couple of forms that replicate the old database container.  Here's a good one.
SortByDesc.zip
0
 
Jeffrey CoachmanCommented:
Again, I am not aware of a direct way that this can be done via VBA.
But perhaps thee is, so let's see what other experts post

And again, is this just for you as the developer?
Most Access Applications are designed so that direct access to the database window/ Task Pane is not needed.

0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
upsfaAuthor Commented:
This is not for end-users, just me a couple of my people.  Actually, I would put this in my blank.accdb template so it is available in any database I create.

Here's where I am going now.  To get to the sort options manually, you can click on the Navigation Pane header, and invoke the context menu by right-clicking.  Alternatively, if the header has the focus, you can use shift-F10 to invoke the menu.  So, I’m thinking sendkeys, although I try to avoid this.  In a macro, I have used the Navigate To function to take me to Tables, then I use shift-tab, four times to move the focus to the header, then use shift-f10, but it does not work.  When I run the macro up to the forth shift-tab line, then manually press shift-F10, it works.  If I manually place the focus on the Navigation Pane header, then run a simple macro that only does the shift-F10 sendkeys command that works, but when I put them together, they it does not work.

Ok, while I was typing that it gave me an idea – create one macro that gives the header the focus, then call another macro that does the shift-F10 part.  It works!

The three macros are attached
Option Compare Database

'------------------------------------------------------------
' SortObjects - This will be run first, it will navigate to the tables section
' of the navigation pane, then will tab up to the navigation pane header, then
' will call the macro that will excute the shift-F10 command to invoke the context menu
'------------------------------------------------------------
Function SortObjects()
On Error GoTo SortObjects_Err

    DoCmd.NavigateTo "acNavigationCategoryObjectType", "acNavigationGroupTables"
    SendKeys "+{Tab}", True
    SendKeys "+{Tab}", True
    SendKeys "+{Tab}", True
    SendKeys "+{Tab}", True
    DoCmd.RunMacro "SortByModDescending", , ""

SortObjects_Exit:
    Exit Function

SortObjects_Err:
    MsgBox Error$
    Resume SortObjects_Exit
End Function
Option Compare Database

'------------------------------------------------------------
' SortByModDescending - This opens the context menu, then selects sort by last modified date
' then opens the menu again and selects Descending, then NavigateTo is used to send the
' focus to the queries section of the navigation pane, then sendkeys is used to give the
' header focus again.  The ShowAllGroups macro is then called to show all object types.
'
'------------------------------------------------------------
Function SortByModDescending()
On Error GoTo SortByModDescending_Err

    SendKeys "+{f10}", False
    SendKeys "{down}", False
    SendKeys "{down}", False
    SendKeys "{right}", False
    SendKeys "{down}", False
    SendKeys "{down}", False
    SendKeys "{down}", False
    SendKeys "{down}", False
    SendKeys "{down}", False
    SendKeys "{enter}", False
    SendKeys "+{F10}", False
    SendKeys "{down}", False
    SendKeys "{down}", False
    SendKeys "{right}", False
    SendKeys "{down}", False
    SendKeys "{enter}", False
    DoCmd.NavigateTo "acNavigationCategoryObjectType", "acNavigationGroupQueries"
    SendKeys "+{tab}", False
    SendKeys "+{tab}", False
    SendKeys "+{tab}", False
    DoCmd.RunMacro "ShowAllGroups", , ""


SortByModDescending_Exit:
    Exit Function

SortByModDescending_Err:
    MsgBox Error$
    Resume SortByModDescending_Exit

End Function


Option Compare Database

'------------------------------------------------------------
' ShowAllGroups - This invokes the context menu and selects Show All Groups
'
'------------------------------------------------------------
Function ShowAllGroups()
On Error GoTo ShowAllGroups_Err

    SendKeys "+{f10}", False
    SendKeys "{down}", False
    SendKeys "{down}", False
    SendKeys "{down}", False
    SendKeys "{down}", False
    SendKeys "{enter}", False

ShowAllGroups_Exit:
    Exit Function

ShowAllGroups_Err:
    MsgBox Error$
    Resume ShowAllGroups_Exit

End Function

Open in new window

0
 
Jeffrey CoachmanCommented:
OK
Great,
If this is what works, then you can accept your own post as the solution.


Just a note here.
MS is always threatening to Deprecate SendKeys.
So be prepared for the day when this becomes a reality...

Jeff
0
 
upsfaAuthor Commented:
It only works when I select the macro manually.  If I add a button to the QAT and use that to run the macro the header does not get the focus (regardeless of how many times I shift-tab).  Really want this to work from the QAT
0
 
Jeffrey CoachmanCommented:
<Really want this to work from the QAT>

Then you may have an uphill battle here.

Again, if it were me, I would just create a standalone form that does this...
0
 
upsfaAuthor Commented:
Victory is mine!

Option Compare Database

'------------------------------------------------------------
' This will sort objects in the database window descending
' by Modified date.
'
' Add this into a module in Access, then
' add an icon for this macro to the Quick Access Tool Bar
' and you will be able to perform the sort with one click so
' you can sort descending by last modified date with one click,
' rather than two right-clicks and four menu selections.
'
'  *  This will not work if your cursor is in a field on
'     a table or query, since CTRL F will then bring up the
'     Find dialog box. Just click on any object in the
'     Navigation Pane, before invoking this code.
'------------------------------------------------------------

Function SortObjects()
On Error GoTo SortObjects_Err

    SendKeys "^f", False
    SendKeys "+{tab}", False
    SendKeys "+{tab}", False
    SendKeys "+{f10}", False
    SendKeys "s", False
    SendKeys "m", False
    SendKeys "{enter}", False
    SendKeys "s", False
    SendKeys "c", False
    SendKeys "{enter}", True
    SendKeys "^f", True
    SendKeys "+{tab}", False
    SendKeys "+{tab}", False
    SendKeys "+{f10}", False
    SendKeys "a", False


SortObjects_Exit:
    Exit Function

SortObjects_Err:
    MsgBox Error$
    Resume SortObjects_Exit

End Function

Open in new window

0
 
upsfaAuthor Commented:
"No body cares more about your problems then you"
0
 
Jeffrey CoachmanCommented:
Congratulations!

Just keep in mind my comments about MS continual threatening to deprecating Send keys...
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
You may find issues with SendKeys in Win 7 ...

mx
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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