473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Basing a menu item on a procedure instead of a function?

Back in the old days before I started learning about menubars (the day
before yesterday,) I based all my operations on command buttons on the
forms. Now the forms are all cluttered up with buttons so I'm beginning to
clean it up using menubars.

So far, I haven't used ANY macros. But some some websites, as well as my
book, seems to indicate that it is necessary to base the menubar on a macro
with each menu's first instruction being AddMenu.

I have made three menus without any macros that seem to work fine (until
now.) Some of my operations don't use forms, but use input boxes and DAO
queries. These operations were stuck in the code behind the forms. I have
a module in the Modules section called, "basMenuStuff," where I'm putting,
of all things, menu stuff. In there I made a subroutine called "NewGroup."
All this does is gets a new group name and group weight from two different
functions, then get a course code from an open form. From these three
pieces of data, it does an INSERT INTO query. That's it. But I got the
following error in a MsgBox:

----------------------------------------------
The object doesn't contain the Automation object "NewGroup."

You tried to run a Visual Basic procedure to set a property or method for an
object.
However, the component doesn't make the property or method available for
Automation operations.

Check the compenent's documentation for information on the properties and
methods it makes available for Automation operations.
|OK|
----------------------------------------------

Is it possible that a menu item cannot be based on a subroutine but must be
based on either in a macro, form, or function?
Nov 13 '05 #1
3 2101
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The easiest way is to set the menu bar item to call a macro. The macro
will be a RunCode macro that calls a VBA function.

You can, also, set the menu bar item's "OnAction" event to a VBA
function, but you have to set up the call programmatically. You'd use
the CommandBar objects & related methods, properties.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQYFFUoechKqOuFEgEQJkhwCg/nm3HTt93ZAdp4eD+78rGkbOj5oAnRjC
1EDlIiIV/PTO4G6bfNV8QSVf
=OXzi
-----END PGP SIGNATURE-----
Richard Hollenbeck wrote:
Back in the old days before I started learning about menubars (the day
before yesterday,) I based all my operations on command buttons on the
forms. Now the forms are all cluttered up with buttons so I'm beginning to
clean it up using menubars.

So far, I haven't used ANY macros. But some some websites, as well as my
book, seems to indicate that it is necessary to base the menubar on a macro
with each menu's first instruction being AddMenu.

I have made three menus without any macros that seem to work fine (until
now.) Some of my operations don't use forms, but use input boxes and DAO
queries. These operations were stuck in the code behind the forms. I have
a module in the Modules section called, "basMenuStuff," where I'm putting,
of all things, menu stuff. In there I made a subroutine called "NewGroup."
All this does is gets a new group name and group weight from two different
functions, then get a course code from an open form. From these three
pieces of data, it does an INSERT INTO query. That's it. But I got the
following error in a MsgBox:

----------------------------------------------
The object doesn't contain the Automation object "NewGroup."

You tried to run a Visual Basic procedure to set a property or method for an
object.
However, the component doesn't make the property or method available for
Automation operations.

Check the compenent's documentation for information on the properties and
methods it makes available for Automation operations.
|OK|
----------------------------------------------

Is it possible that a menu item cannot be based on a subroutine but must be
based on either in a macro, form, or function?


Nov 13 '05 #2
"Richard Hollenbeck" <ri****************@verizon.net> wrote in message
news:iKagd.14036$5O4.2722@trnddc07...
Back in the old days before I started learning about menubars (the day
before yesterday,) I based all my operations on command buttons on the
forms. Now the forms are all cluttered up with buttons so I'm beginning
to
clean it up using menubars.
Great stuff. I also find that menus can significantly clean up those forms.

So far, I haven't used ANY macros. But some some websites, as well as my
book, seems to indicate that it is necessary to base the menubar on a
macro
with each menu's first instruction being AddMenu.


No, not all. As a general rule, I simply have all my menus call custom code.
That code can be in the forms module, or a general module.

In most cases, if the menu bar code is for the current form..then it makes
sense that the code belongs in the forms module..and not some other module.

Here is a few other points:

You do in fact have to use a function name..and you can't use a sub-name. If
you already got some extensive sub code written, you then just create a
function that calls the code.

The functions in the form have to be public. For example, MOST of my forms
have some custom delete code, and I ALWAYS call it

Public Function MyDelete
The advance of ALWAYS using the same function name should not be missed. If
you have a custom menu bar, then to call the forms code you put the function
name in the menu "on action" (I create all my menus via drag and drop with
the mouse by the way!).

So, to run the MyDelete function, you just type in the following into the
menus "on action" property setting:

=MyDelete()

The above goes in the on-action. What is very cool here is that this means
that ONE menu bar can apply to several forms. Which ever form has the focus
will have its public function called MyDelete() run. And, if the form does
NOT have a public function, then a function of the above name in a standard
module is tried to run. So, for example, you could write a common delete
function that applies to ALL forms,a and place the code in a standard
module. However, lets assume you have one form that needs special
treatment...you just then put a public function in the forms module of the
same name..and that one gets run!

Further, a LOT of my menu code is in standard modules, and some is in forms
module. If the code goes into a forms module, then you code can use things
like:

me.Refresh

or me.InvoiceNumber

However, for code in a general module..you can't use "me", so you what you
do is simply pick up the currently active form.

So, for "general" code, my code almost always grabs the active form...here
is a example for a invoice print option:

Dim tblgroupid As Long
Dim frmActive As Form

Set frmActive = Screen.ActiveForm

tblgroupid = frmActive.frmMainClientB.Form!ID

If frmActive.InvoiceNumber = 0 Then
frmActive.InvoiceNumber = nextinvoice
frmActive.Refresh
End If

DoCmd.OpenForm "guiInvoicePrint", , , "id = " & tblgroupid
So, you can see that the trick here is to "pick up" the currently active
screen, and make a form ref that you can use. As mentioned, if you place
your menu bar code in the actual forms module..then you can use "me".

Here is some other ideas and screen shots of menu bars I made in ms-access
(all were created via drag and drop).

http://www.attcanada.net/~kallal.msn...erFriendly.htm
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.attcanada.net/~kallal.msn
Nov 13 '05 #3
Thank you. Great reply!
Rich

"Albert D. Kallal" <Pl*******************@msn.com> wrote in message
news:k8mgd.48492$%k.19372@pd7tw2no...
"Richard Hollenbeck" <ri****************@verizon.net> wrote in message
news:iKagd.14036$5O4.2722@trnddc07...
Back in the old days before I started learning about menubars (the day
before yesterday,) I based all my operations on command buttons on the
forms. Now the forms are all cluttered up with buttons so I'm beginning
to
clean it up using menubars.
Great stuff. I also find that menus can significantly clean up those

forms.

So far, I haven't used ANY macros. But some some websites, as well as my book, seems to indicate that it is necessary to base the menubar on a
macro
with each menu's first instruction being AddMenu.
No, not all. As a general rule, I simply have all my menus call custom

code. That code can be in the forms module, or a general module.

In most cases, if the menu bar code is for the current form..then it makes
sense that the code belongs in the forms module..and not some other module.
Here is a few other points:

You do in fact have to use a function name..and you can't use a sub-name. If you already got some extensive sub code written, you then just create a
function that calls the code.

The functions in the form have to be public. For example, MOST of my forms
have some custom delete code, and I ALWAYS call it

Public Function MyDelete
The advance of ALWAYS using the same function name should not be missed. If you have a custom menu bar, then to call the forms code you put the function name in the menu "on action" (I create all my menus via drag and drop with
the mouse by the way!).

So, to run the MyDelete function, you just type in the following into the
menus "on action" property setting:

=MyDelete()

The above goes in the on-action. What is very cool here is that this means that ONE menu bar can apply to several forms. Which ever form has the focus will have its public function called MyDelete() run. And, if the form does
NOT have a public function, then a function of the above name in a standard module is tried to run. So, for example, you could write a common delete
function that applies to ALL forms,a and place the code in a standard
module. However, lets assume you have one form that needs special
treatment...you just then put a public function in the forms module of the
same name..and that one gets run!

Further, a LOT of my menu code is in standard modules, and some is in forms module. If the code goes into a forms module, then you code can use things
like:

me.Refresh

or me.InvoiceNumber

However, for code in a general module..you can't use "me", so you what you
do is simply pick up the currently active form.

So, for "general" code, my code almost always grabs the active form...here
is a example for a invoice print option:

Dim tblgroupid As Long
Dim frmActive As Form

Set frmActive = Screen.ActiveForm

tblgroupid = frmActive.frmMainClientB.Form!ID

If frmActive.InvoiceNumber = 0 Then
frmActive.InvoiceNumber = nextinvoice
frmActive.Refresh
End If

DoCmd.OpenForm "guiInvoicePrint", , , "id = " & tblgroupid
So, you can see that the trick here is to "pick up" the currently active
screen, and make a form ref that you can use. As mentioned, if you place
your menu bar code in the actual forms module..then you can use "me".

Here is some other ideas and screen shots of menu bars I made in ms-access
(all were created via drag and drop).

http://www.attcanada.net/~kallal.msn...erFriendly.htm
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.attcanada.net/~kallal.msn

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Marek Mand | last post by:
How to create a functional *flexible* UL-menu list <div> <ul> <li><a href=""></li> <li><a href=""></li> <li><a href=""></li> </ul> </div> (working in IE, Mozilla1.6, Opera7 (or maybe even...
10
by: John Ortt | last post by:
Hi Everyone, I have created a Javascript menu for my site which uses frames. The first stage loads fine but I want two drill down menus ("About Me Menu" and "Projects Menu"). The pages load...
2
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at...
3
by: unurban | last post by:
I have a javascript menu based off of unordered lists that only shows the subnav links when you click on the main nav links. is there a way to keep any subnav items open after you click on a link...
3
by: scaredemz | last post by:
hi, so i'm creating a dynamic drop-down menu. the menu and the text show up fine in IE but only the drop-down shows in Firefox without the menu text. Below is the fxn code. help pls. function...
7
by: joecap5 | last post by:
I have a main window from which I want to open a separate side menu window. I then want to create a list of items on that side menu by clicking on the item names in the main window. So far I am...
1
by: Kayvine | last post by:
Hi guys, this is a question I have for an assignment, it is pretty long, but I am not asking for the code(well if someone wants to write I'll be really happy, lol), but I just want to know how to...
0
by: rahullko05 | last post by:
i have designed a menu list program in which i'm facing a problem where the last li item (white crappie) shifts down when i hover mouse pointer to just above li item (ozrack bazz) of white crappie...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.