Menu bar (not using Macros)

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

I am new to programming in Access but am keen to try and use more, rather
than macro's.

I would like to customize my own menu bar for a form. I cannot however get
this to work. Could someone give me an example piece of code that will just
put File --> Open in a menu bar, that can be put into the On load event of a
form, to help me understand how the functionality works, once I understand
that hopefully I can build more complex menus.

Thank you in advnace.

Chris
 
Sub MyMainMenu(
'main menu commandba
Dim cb As CommandBa
Dim ctr As CommandBarContro
Dim i As Lon

On Error Resume Nex
'pasek istnieje/commandbar exist
Set cb = CommandBars("MojPasekMenu"
'jeśli istnieje usuń, by na nowo go utworzyć/if exist then delete it and create new on
If Not cb Is Nothing Then UsunPasek "MojPasekMenu

On Error GoTo Err_MyMainMen
'utówrz nowy pasek/create new commandba
Set cb = CommandBars.Add("MojPasekMenu", msoBarTop, True, True) 'temporary menu ba
'utwórz nowy element typu menu rozwijane/create new commadbarcontrol type popu
Set ctr = cb.Controls.Add(msoControlPopup
With ct
.Caption = "Some
.TooltipText = .Captio
For i = 1 To
ctr.Controls.Add msoControlButto
Next
With ctr.Control
'1 el
.Item(1).Caption = "Nowy
.Item(1).TooltipText = .Item(1).Captio
.Item(1).FaceId = 18 'ikona nowy/icon ne
.Item(1).OnAction = "NewEle_Click" 'makro, które będzie uruchomione przy kliknięciu/macro to ru
'2 el
.Item(2).Caption = "Otwórz
.Item(2).TooltipText = .Item(2).Captio
.Item(2).FaceId = 23 'ikona otwórz/icon ope
.Item(2).OnAction = "OpenEle_Click" 'makro, które będzie uruchomione przy kliknięciu/macro to ru
'3 el
.Item(3).Caption = "Zamknij
.Item(3).TooltipText = .Item(3).Captio
.Item(3).FaceId = 106 'ikona zamknij/icon clos
.Item(3).OnAction = "CloseEle_Click" 'makro, które będzie uruchomione przy kliknięciu/macro to ru
End Wit

End Wit

cb.Visible = Tru

Exit_MyMainMenu
On Error Resume Nex
Set ctr = Nothin
Set cb = Nothin
Exit Su
Err_MyMainMenu
MsgBox Err.Description, vbExclamation, "BÅ‚Ä…d nr " & Err.Numbe
Resume Exit_MyMainMen
End Su

Sub MyToolBar(
'simple commandbar (not main menu
Dim cb As CommandBa
Dim ctr As CommandBarContro

On Error Resume Nex
Set cb = CommandBars("MojPasekNarz"
If Not cb Is Nothing Then UsunPasek "MojPasekNarz

On Error GoTo Err_MyToolBa

Set cb = CommandBars.Add("MojPasekNarz", msoBarTop

'1 el
Set ctr = cb.Controls.Add(msoControlButton
With ct
.Caption = "Nowy
.TooltipText = .Captio
.FaceId = 18 'nowy/ne
.OnAction = "NewEle_Click
End Wit

'2 el
Set ctr = cb.Controls.Add(msoControlButton
With ct
.Caption = "Otwórz
.TooltipText = .Captio
.FaceId = 23 'otwórz/ope
.OnAction = "OpenEle_Click
End Wit

'3 el
Set ctr = cb.Controls.Add(msoControlButton
With ct
.Caption = "Zamknij
.TooltipText = .Captio
.FaceId = 106 'zamknij/clos
.OnAction = "CloseEle_Click
End Wit

cb.Visible = Tru

Exit_MyToolBar
On Error Resume Nex
Set ctr = Nothin
Set cb = Nothin
Exit Su
Err_MyToolBar
MsgBox Err.Description, vbExclamation, "BÅ‚Ä…d nr " & Err.Numbe
Resume Exit_MyToolBa
End Su
 
Chris said:
I am new to programming in Access but am keen to try and use more, rather
than macro's.

I would like to customize my own menu bar for a form. I cannot however get
this to work. Could someone give me an example piece of code that will just
put File --> Open in a menu bar, that can be put into the On load event of a
form, to help me understand how the functionality works, once I understand
that hopefully I can build more complex menus.

Why not just use the access UI to build the menu bar, and then ATTACH code?
That is WAY less work.

You can build all kinds of cool menu bars...and have any of the
buttons/options on the bar run your code. So, I not sure really if you need
to start using code to make menu bars. It is kind of like using code to make
a form..you *can* use code to make a form..but usually you are far better
off to build the form..and then attached code to it...

If you use the access UI to make a menu bar, then you can specify that menu
bar for the particular form in the "other" tab. And, to have a menu bar run
YOUR code, you simply put the function name in the menu's on-action
property. All this can be done without writing any code.

Here is a tutorial for some menu bars:

http://www.microsoft.com/Accessdev/articles/bapp97/chapters/ba01_6.htm
 
Back
Top