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