473,378 Members | 1,478 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,378 software developers and data experts.

Custom Menu Code In Form??

I have a custom menu that is only used for one form. Is there a way to put
the functions for the menu items in the form's module rather than a standard
module?

Thanks!

Judy
Nov 13 '05 #1
2 1383
Yes, you most certainly can do this. (and, in fact, as you ask..it is a good
idea!).

The solution is quite simple:

Simply make the function names public, and then place them in the form.

eg:
Public Function MyDelete()

' delete customer?

Dim strSql As String
Dim intShifts As Integer

If MsgBox("Do you want to delete this customer?" & vbCrLf & _
vbCrLf & _
"This will remove this customer" & vbCrLf & _
"You can NOT undo this!", vbCritical + vbYesNoCancel, "Delete
Customerr") = vbYes Then
Me.Undo
If IsNull(Me.ID) = False Then
strSql = "delete * from tblCustomer where id = " & Me.ID
CurrentDb.Execute strSql
endif
End If
DoCmd.Close acForm, Me.Name
End If

End Function

So, the above code will delete the record you are viewing..and I also have
the above to close the form.

You then in your menu bar, simply place the name of the above function in
the "on action" setting the of menu, so:

=MyDelete()

Thus, the above is all you need. As side note, you do NOT want to qualify
the form, and function names with a full pathname like:

forms!frmMyCusttomer.MyDelete()

Just use the function name:

=MyDelete()

Also, the real nice feature of this is in fact that you can make a
consistent function name to "delete" and each form can thus have a public
function called MyDelete(). This means in effect that you can make custom
menus that apply to more then one screen if you use a consistent function
name. Whatever form has the current focus will thus run the MyDelete()
function.
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.attcanada.net/~kallal.msn
Nov 13 '05 #2
FANTASTIC!!!

You just made my scheduling calendar easily portable to other applications.

Thanks Much!

Judy

"Albert D. Kallal" <Pl*******************@msn.com> wrote in message
news:#u**************@tk2msftngp13.phx.gbl...
Yes, you most certainly can do this. (and, in fact, as you ask..it is a good idea!).

The solution is quite simple:

Simply make the function names public, and then place them in the form.
eg:
Public Function MyDelete()

' delete customer?

Dim strSql As String
Dim intShifts As Integer

If MsgBox("Do you want to delete this customer?" & vbCrLf & _
vbCrLf & _
"This will remove this customer" & vbCrLf & _
"You can NOT undo this!", vbCritical + vbYesNoCancel, "Delete
Customerr") = vbYes Then
Me.Undo
If IsNull(Me.ID) = False Then
strSql = "delete * from tblCustomer where id = " & Me.ID
CurrentDb.Execute strSql
endif
End If
DoCmd.Close acForm, Me.Name
End If

End Function

So, the above code will delete the record you are viewing..and I also have the above to close the form.

You then in your menu bar, simply place the name of the above function in
the "on action" setting the of menu, so:

=MyDelete()

Thus, the above is all you need. As side note, you do NOT want to qualify
the form, and function names with a full pathname like:

forms!frmMyCusttomer.MyDelete()

Just use the function name:

=MyDelete()

Also, the real nice feature of this is in fact that you can make a
consistent function name to "delete" and each form can thus have a public
function called MyDelete(). This means in effect that you can make custom
menus that apply to more then one screen if you use a consistent function
name. Whatever form has the current focus will thus run the MyDelete()
function.
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.attcanada.net/~kallal.msn

Nov 13 '05 #3

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

Similar topics

2
by: Sean Mullaly | last post by:
I have a custom Access menu with sub-menus and sub-sub-menus. (220 items). Right now I have created 220 Functions and attached each individual Function to the specific OnAction property. The...
4
by: jesse.hartwick | last post by:
Hey group! I have a toolbar with a "DEVELOPER" menu. I have it so that it when the menu title is clicked, a pop-up form will appear if the user has not yet verified that he or she has developer...
7
by: Girish | last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a huge learning experience.. My problem. I have a requirement to display a gird with a gird. Within the embedded grid,...
0
by: R.A.M. | last post by:
Hello, I need your help with a problem concerning Menu control. Could you help me please? I have created custom Menu: public class DemoMenu : Menu { public DemoMenu(string ID, string...
27
by: Wayne | last post by:
I've been clicking around Access 2007 Beta 2 and can't see the custom menu bar designer. Is it in the beta? Maybe I'm blind. The question that comes to mind is: Will custom menu bars be the same...
2
by: Keith Hutchison | last post by:
G'day Is it possible to do custom context sensitive menus within MS Access. If yes, does anyone have a sample example? Thanks in advance Keith
2
by: trialproduct2004 | last post by:
Hi all, I am having application in whihc i am inserting menuitem dynamically. When i add menuitem to mainmenu, i want to pass extra parameter to eventargs. So what i did is derived class from...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?

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.