Command Bar

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

Dear all,

I have two problem for command bar setting:

1) how to set the sub menu bar by coding ?

2) I want to set the menu bar at the top of the screen by following coding,
but it doesn't work.

set cb = commandbars("abc menu", msoBarTop,,True)

Thank you.
Jason.
 
Hi Jason,
Regarding your two questions, please see my answers below:
Q: how to set the sub menu bar by coding ?
A: Try the following code:
================================
Dim cb As CommandBar

Set cb = Application.CommandBars.Add("abc menu", msoBarTop, True, True)
Set cbSubMenu = cb.Controls.Add(Type:=10)
With cbSubMenu
.Caption = "Test"
.BeginGroup = True
End With
Set cbsubCtl = cbSubMenu.Controls.Add(Type:=msoControlButton)
With cbsubCtl
.Caption = "Hello World"
.FaceId = 1
End With
cb.Visible = True
================================

Q: I want to set the menu bar at the top of the screen by following
coding, but it doesn't work. set cb = commandbars("abc menu",
msoBarTop,,True)
A: Per my above test, the menu bar is at the top of tyhe main Access
window. Could you please let me know why you would like to move the menu
bar at the top of the screen? Per my knowledge, you need to call Windows
API to move your main Access window to the top of the screen so that the
title of your Access window can be hidden.
For example:
'First create a module to re-declare the related Win32 API
================================
Public Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As
Long) As Long

Private Declare Function apiFindWindow Lib "user32" Alias _
"FindWindowA" (ByVal strClass As String, _
ByVal lpWindow As String) As Long

Public Declare Function apiMoveWindow Lib "user32" Alias "MoveWindow"
(ByVal hWnd As Long, ByVal X As Long, ByVal Y As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As
Long
================================

'Then move your window to hide the title
==================================
Dim nHeight, nSX, nSY As Long

Dim nRet As Long
Dim hWnd As Long

hWnd = Module4.apiFindWindow(vbNullString, "Microsoft Access")

nHeight = Module4.GetSystemMetrics(31)
nSX = Module4.GetSystemMetrics(0)
nSY = Module4.GetSystemMetrics(1)

nRet = Module4.apiMoveWindow(hWnd, 0, 0 - CInt(1.5 * nHeight), nSX, nSY +
nHeight, True)
===================================

You may also want the following reference:
http://www.mvps.org/access/api/api0007.htm

Hope this helps. If you have any other questions or concerns, please feel
free to let me know.

Best regards,
Charles Wang
Microsoft Online Community Support
===========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: (e-mail address removed).
===========================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for
non-urgent issues where an initial response from the community
or a Microsoft Support Engineer within 1 business day is acceptable.
Please note that each follow up response may take approximately
2 business days as the support professional working with you may
need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by
contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
============================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
 
Hi Charles,

Thank you very for your help.

for 1st question, I've tried your code and it's worked to create sub menu.
But when processing the statement "Set cbsubCtl =
cbSubMenu.Controls.Add(Type:=msoControlButton)", error is occurred. And I
tried to change the statement "Set cbsubCtl = cbSubMenu.Controls.Add", It's
OK.
Do you know why ?

for 2nd question, I'm sorry to confuse you. I want to set menu bar is at the
top of the Access windows(not the top of the screen). But It doesn't work.
The menu bar is set to the left of the access windows.

Thanks & Regards,
Jason

"Charles Wang [MSFT]" said:
Hi Jason,
Regarding your two questions, please see my answers below:
Q: how to set the sub menu bar by coding ?
A: Try the following code:
================================
Dim cb As CommandBar

Set cb = Application.CommandBars.Add("abc menu", msoBarTop, True, True)
Set cbSubMenu = cb.Controls.Add(Type:=10)
With cbSubMenu
.Caption = "Test"
.BeginGroup = True
End With
Set cbsubCtl = cbSubMenu.Controls.Add(Type:=msoControlButton)
With cbsubCtl
.Caption = "Hello World"
.FaceId = 1
End With
cb.Visible = True
================================

Q: I want to set the menu bar at the top of the screen by following
coding, but it doesn't work. set cb = commandbars("abc menu",
msoBarTop,,True)
A: Per my above test, the menu bar is at the top of tyhe main Access
window. Could you please let me know why you would like to move the menu
bar at the top of the screen? Per my knowledge, you need to call Windows
API to move your main Access window to the top of the screen so that the
title of your Access window can be hidden.
For example:
'First create a module to re-declare the related Win32 API
================================
Public Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As
Long) As Long

Private Declare Function apiFindWindow Lib "user32" Alias _
"FindWindowA" (ByVal strClass As String, _
ByVal lpWindow As String) As Long

Public Declare Function apiMoveWindow Lib "user32" Alias "MoveWindow"
(ByVal hWnd As Long, ByVal X As Long, ByVal Y As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As
Long
================================

'Then move your window to hide the title
==================================
Dim nHeight, nSX, nSY As Long

Dim nRet As Long
Dim hWnd As Long

hWnd = Module4.apiFindWindow(vbNullString, "Microsoft Access")

nHeight = Module4.GetSystemMetrics(31)
nSX = Module4.GetSystemMetrics(0)
nSY = Module4.GetSystemMetrics(1)

nRet = Module4.apiMoveWindow(hWnd, 0, 0 - CInt(1.5 * nHeight), nSX, nSY +
nHeight, True)
===================================

You may also want the following reference:
http://www.mvps.org/access/api/api0007.htm

Hope this helps. If you have any other questions or concerns, please feel
free to let me know.

Best regards,
Charles Wang
Microsoft Online Community Support
===========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: (e-mail address removed).
===========================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for
non-urgent issues where an initial response from the community
or a Microsoft Support Engineer within 1 business day is acceptable.
Please note that each follow up response may take approximately
2 business days as the support professional working with you may
need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by
contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
============================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
 
Hi Jason,
Regarding cbSubMenu.Controls.Add(Type:=msoControlButton) and
cbSubMenu.Controls.Add, they are essentially same, since msoControlButton
is just the default value if you do not explicitly specify it.

Regarding your 2nd question, could you please let me know what the version
of your Access is? My test is based on Access 2003. For Access 2007 Ribbon
UI, the things will be different, the menu created via the above method
will be placed under the tab named "Add-in'. However I have not found that
it was placed to the left of the Access window.

If possible, you may mail me (changliw_at_microsoft_dot_com) a screenshot
and your Access sample database for further research.

Best regards,
Charles Wang
Microsoft Online Community Support
=========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: (e-mail address removed).
=========================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
 
Back
Top