Creating shortcuts and shortcut groups with VBA?

  • Thread starter Thread starter Jeff Kowalczyk
  • Start date Start date
J

Jeff Kowalczyk

I've been googling for two days to see if I can find this out on my own,
but the common uses of 'groups' and 'shortcuts' is clouding the search.

Is there a VBA appliction object in Access 2002 that will allow me to
create shortcuts (and groups for shortcuts) as I iterate over my
querydefs? There does not seem to be a macro command. There is a menu
command, so I would expect VBA automation to be able to touch it.

I'm referring to the internal groupings you can create in Access, not
Windows/Internet favorites.

Thanks for any information.
 
Sorry, that is not very clear. What exactly do you mean by a "group" and a
"shortcut" in this context? What menu command are you referring to?

TC
 
In Access XP (2002), there are user-definable 'groups' on the left-hand
side of the database objects window (below tables, queries, forms, etc).
By default the only group is 'Favorites', but you can create your own
groups from menu commands. You can then create shortcuts (which look like
windows shortcuts, but are stored internally in the MDB), that point to
individual queries, reports, forms, or other database objects.

I need an automated way to erase all existing shortcuts, and then
re-create them from VBA code. I have over a hundred query objects that I
want to organize within related groups (based on the first few characters
of their names), since there are too many to reasonably look at them all
in the unsorted 'queries' view. I need to write a VBA 'refresh shortcuts'
routine that can be run after new queries are created or renamed to belong
to a different logical group. I'm looking for the API to find, erase and
create these groups and shortcuts.

Thanks very much for responding, and if that still isn't clear, I'll try
to explain it further.
 
Hi Jeff,

There is no Object Model for the Groups/shortcuts and therefore no easy way
to deal with them programmatically; however, we can simulate the menu
action; perhaps that does some help to your problem:

Sample code
========

' Add the Employes table to the group "MYGROUP", MYGROUP is the group
just below favorites

DoCmd.SelectObject acTable, "Employees", True

' Shift+F10 will drop the context menu

' AA to get to Add to Group

' {RIGHT} to expand the sub menu

' 2 because the group you are creating is the second group.

SendKeys "+{F10}AA{RIGHT}2", True

' Add the myReport report to the group

DoCmd.SelectObject acReport, "MyReport", True

SendKeys "+{F10}AA{RIGHT}2", True

MsgBox "The shortcuts have been created."

Please feel free to reply to the threads if you have any concerns or
question.



Sincerely,

Alick Ye, MCSD
Product Support Services
Microsoft Corporation
Get Secure! - <www.microsoft.com/security>

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| From: Jeff Kowalczyk <[email protected]>
| Subject: Creating shortcuts and shortcut groups with VBA?
| Date: Fri, 03 Oct 2003 11:44:31 -0400
| X-Tomcat-NG: microsoft.public.access.modulesdaovba
|
| I've been googling for two days to see if I can find this out on my own,
| but the common uses of 'groups' and 'shortcuts' is clouding the search.
|
| Is there a VBA appliction object in Access 2002 that will allow me to
| create shortcuts (and groups for shortcuts) as I iterate over my
| querydefs? There does not seem to be a macro command. There is a menu
| command, so I would expect VBA automation to be able to touch it.
|
| I'm referring to the internal groupings you can create in Access, not
| Windows/Internet favorites.
|
| Thanks for any information.
|
 
Thanks for the clarification. I've not used 2002 much, so I am
unfortunately not familiar with the feature you describe. Hopefully
someone else can help. I assume you've checked online help under
"groups" & similar likely keywords?

TC
 
Thanks very much for the reply, Alick. While it's pretty frustrating to
have a major UI element unavailable from the object model (and it still
is in Office 2003, it appears), I do appreciate the tips on the sendkey
method, which I've never worked with before. The create shortcut by
name works well, thank you.

To make this work, I need a routine to build and teardown all shortcut
groups as part of the query maintenance. I have a table of groups to
iterate over, but knowing how to do it with a single string name will be a
good starting point. DoCmd.RunCommand acCMDNewGroup doesn't seem to take
any parameters, and being modal, won't give control back to sendkeys.

Sub createqueryshortcutgroup(groupname AS String)
DoCmd.RunCommand acCmdNewGroup
SendKeys groupname ' And what would press the OK button?
End Sub

Sub deletequeryshortcutgroup(groupname AS String)
' need to select group by name, or index in my list if need be
DoCmd.RunCommand acCmdDeleteGroup
SendKeys "" ' what would press the OK button to confirm?
End Sub

Thanks for any help with these routines.
 
Hi Jeff,

To simulate the clicking OK button action, we can try sendmessage APIs;
first we call FindWindow, FindWindowEx to find the dialog window and send
the text to the edit window and then send BM_CLICK message to the dialog to
click OK and close. I developed a sample for your reference. This sample
creates a new group automatically.

Note: I use command object to start the menu action. (Edit->Add to
Group->New Group..)

Sample Code
========

Option Compare Database
Option Explicit

Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As
Long

Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWndParent As Long, ByVal hwndChildAfter As Long, ByVal lpszClass As
_
String, ByVal lpszWindow As String) As Long

Private Declare Function SendDlgItemMessage Lib "user32" Alias
"SendDlgItemMessageA" (ByVal hDlg As Long, ByVal nIDDlgItem As Long, ByVal
wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Const WM_SETTEXT = &HC

'#define BM_CLICK 0x00F5
Private Const BM_CLICK = &HF5

Private Sub Command0_Click()

'pop the create new group window.

On Error GoTo ErrorHandle3

Dim CBarMenu As CommandBar

Dim CBarCtl As CommandBarPopup

Set CBarMenu = Application.CommandBars("Menu Bar")

Set CBarCtl = CBarMenu.Controls("Edit")

Set CBarCtl = CBarCtl.Controls("Groups")

Me.TimerInterval = 500


CBarCtl.Controls("New Group...").Execute


Exit Sub

ErrorHandle3:

Exit Sub


End Sub

Private Sub Form_Timer()

Dim x As String
Dim h As Long, ed As Long

x = "mygroupname"

h = FindWindow("#32770", "New Group")
Debug.Print h

If h <> 0 Then
ed = FindWindowEx(h, 0, "RichEdit20W", "")

Debug.Print ed

SendMessage ed, WM_SETTEXT, ByVal 0, ByVal x

ed = FindWindowEx(h, 0, "Button", "OK")

SendDlgItemMessage h, vbOK, BM_CLICK, ByVal 0&, ByVal 0&

Else

Debug.Print "can't find the new group window"

End If

Me.TimerInterval = 0


End Sub





Sincerely,

Alick Ye, MCSD
Product Support Services
Microsoft Corporation
Get Secure! - <www.microsoft.com/security>

This posting is provided "AS IS" with no warranties, and confers no rights.




--------------------
| From: Jeff Kowalczyk <[email protected]>
| Subject: RE: Creating shortcuts and shortcut groups with VBA?
|
| Thanks very much for the reply, Alick. While it's pretty frustrating to
| have a major UI element unavailable from the object model (and it still
| is in Office 2003, it appears), I do appreciate the tips on the sendkey
| method, which I've never worked with before. The create shortcut by
| name works well, thank you.
|
| To make this work, I need a routine to build and teardown all shortcut
| groups as part of the query maintenance. I have a table of groups to
| iterate over, but knowing how to do it with a single string name will be a
| good starting point. DoCmd.RunCommand acCMDNewGroup doesn't seem to take
| any parameters, and being modal, won't give control back to sendkeys.
|
| Sub createqueryshortcutgroup(groupname AS String)
| DoCmd.RunCommand acCmdNewGroup
| SendKeys groupname ' And what would press the OK button?
| End Sub
|
| Sub deletequeryshortcutgroup(groupname AS String)
| ' need to select group by name, or index in my list if need be
| DoCmd.RunCommand acCmdDeleteGroup
| SendKeys "" ' what would press the OK button to confirm?
| End Sub
|
| Thanks for any help with these routines.
|
| On Mon, 06 Oct 2003 04:39:48 +0000, Alick [MSFT] wrote:
| > There is no Object Model for the Groups/shortcuts and therefore no easy
way
| > to deal with them programmatically; however, we can simulate the menu
| > action; perhaps that does some help to your problem:
| > Sample code
| > ' Add the Employes table to the group "MYGROUP", MYGROUP is the
group
| > just below favorites
| > DoCmd.SelectObject acTable, "Employees", True
| > ' Shift+F10 will drop the context menu
| > ' AA to get to Add to Group
| > ' {RIGHT} to expand the sub menu
| > ' 2 because the group you are creating is the second group.
| > SendKeys "+{F10}AA{RIGHT}2", True
| > ' Add the myReport report to the group
| > DoCmd.SelectObject acReport, "MyReport", True
| > SendKeys "+{F10}AA{RIGHT}2", True
| > MsgBox "The shortcuts have been created."
| > Please feel free to reply to the threads if you have any concerns or
| > question.
|
 
Back
Top