473,732 Members | 2,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to run a module using a menu bar

jpr
Hello,

I have created menu bars for my access application and now would like
to transfer many pieces of code in modules so that they can run using
macros. I beleive this is the only way I can make run my code from the
menu bar. Correct?

I am having problems with the modules since I have never used them and
would like some help.

Here is a sample of code I now have on a push button in a form:

Dim mydb As DAO.Database, MyRs As DAO.Recordset
Dim strCode As String
Dim strFilter As String
Dim stDocName As String
Dim stLinkCriteria As String

Set mydb = CurrentDb
Set MyRs = mydb.OpenRecord set("master")

stDocName = "MASTER"

stLinkCriteria = "[SSN]=" & "'" & Me![SSN] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
If Not IsNull(DLookup( "[SSN]", "TEMPLATES" , "[SSN] = '" & Me!SSN &
"'")) Then
Forms("EFORMS") .Visible = False
Else
If IsNull(DLookup( "[SSN]", "TEMPLATES" , "[SSN] = '" & Me!SSN & "'"))
Then
DoCmd.OpenQuery ("Appendtemplat es")
End If
End If

If Not IsNull(DLookup( "[SSN]", "195", "[SSN] = '" & Me!SSN & "'")) Then
Forms("EFORMS") .Visible = False
Else
If IsNull(DLookup( "[SSN]", "195", "[SSN] = '" & Me!SSN & "'")) Then
DoCmd.OpenQuery ("Append195" )
End If
End If

If Not IsNull(DLookup( "[SSN]", "795", "[SSN] = '" & Me!SSN & "'")) Then
Forms("EFORMS") .Visible = False
Else
If IsNull(DLookup( "[SSN]", "795", "[SSN] = '" & Me!SSN & "'")) Then
DoCmd.OpenQuery ("Append795" )
End If
End If

If Not IsNull(DLookup( "[SSN]", "21", "[SSN] = '" & Me!SSN & "'")) Then
Forms("EFORMS") .Visible = False
Else
If IsNull(DLookup( "[SSN]", "21", "[SSN] = '" & Me!SSN & "'")) Then
DoCmd.OpenQuery ("Appendssa21ta x")

End If
End If
Forms!eforms.ls tPreInterview.V alue = Null
DoCmd.Close
DoCmd.OpenForm ("Eforms")
DoCmd.RunMacro ("CloseEform s")
DoCmd.OpenForm ("Eforms")

End Sub

What I need is to add this code to a module, and make it run using a
manu bar (I assume via macro). Thanks.

Aug 26 '06 #1
4 8673
jpr wrote:
Hello,

I have created menu bars for my access application and now would like
to transfer many pieces of code in modules so that they can run using
macros. I beleive this is the only way I can make run my code from the
menu bar. Correct?
Incorrect. 8)
What I need is to add this code to a module, and make it run using a
manu bar (I assume via macro). Thanks.
Generally, code that sits in standard modules is available all the time,
regardless of what forms are opened. The sub you have with your button
on a form is in the form module for that form and is only available when
your form is open.

First create a standard module and save it. Cut your procedure from the
form module it is in and paste it to the standard module and save your mdb.

To be able to run your procedure from a menu bar control, it must be a
function. Change it from Sub Whatever to:

Public Function fProcedure()

<blah blah>

End Function

To make this run from your menu, go to the customize dialog, right click
the menu control and choose properties.

In the on action control, put in:

=fProcedure()

You can also include arguments as well.

Hope this gets you going.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Aug 27 '06 #2
jpr
thanks for your help. I have followed your advise but still getting an
error message:
"The expression you have entered has a function that MS Office can't
fint"

Any idea of what is wrong based on my code? THanks.
Tim Marshall wrote:
jpr wrote:
Hello,

I have created menu bars for my access application and now would like
to transfer many pieces of code in modules so that they can run using
macros. I beleive this is the only way I can make run my code from the
menu bar. Correct?

Incorrect. 8)
What I need is to add this code to a module, and make it run using a
manu bar (I assume via macro). Thanks.

Generally, code that sits in standard modules is available all the time,
regardless of what forms are opened. The sub you have with your button
on a form is in the form module for that form and is only available when
your form is open.

First create a standard module and save it. Cut your procedure from the
form module it is in and paste it to the standard module and save your mdb.

To be able to run your procedure from a menu bar control, it must be a
function. Change it from Sub Whatever to:

Public Function fProcedure()

<blah blah>

End Function

To make this run from your menu, go to the customize dialog, right click
the menu control and choose properties.

In the on action control, put in:

=fProcedure()

You can also include arguments as well.

Hope this gets you going.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Aug 28 '06 #3
jpr wrote:
thanks for your help. I have followed your advise but still getting an
error message:
"The expression you have entered has a function that MS Office can't
fint"
The function (do NOT use a sub, it MUST BE a function) is spelt
incorrectly, or is not public or is not saved in a standard module.
Also, the = sign and the closing parenthesis must be used.

So, the following will cause the error you mentioned if entered into the
on action control:

fProcedure() <WRONG>

fProcedure <WRONG>

=fProcedure <WRONG>

You must enter:

=fProcedure() <CORRECT>

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Aug 28 '06 #4
Just for the record: you can't run a Module. A Module is a container for
code, and the code in a Module is organized into Procedures (Sub or
Function) and a General Area that can contain Variables and Constants.

You can run a Procedure that exists in a Module. You should NOT give a
Module and a Procedure the same name.

Larry Linson
Microsoft Access MVP
"jpr" <jp***@tin.itwr ote in message
news:11******** **************@ b28g2000cwb.goo glegroups.com.. .
Hello,

I have created menu bars for my access application and now would like
to transfer many pieces of code in modules so that they can run using
macros. I beleive this is the only way I can make run my code from the
menu bar. Correct?

I am having problems with the modules since I have never used them and
would like some help.

Here is a sample of code I now have on a push button in a form:

Dim mydb As DAO.Database, MyRs As DAO.Recordset
Dim strCode As String
Dim strFilter As String
Dim stDocName As String
Dim stLinkCriteria As String

Set mydb = CurrentDb
Set MyRs = mydb.OpenRecord set("master")

stDocName = "MASTER"

stLinkCriteria = "[SSN]=" & "'" & Me![SSN] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
If Not IsNull(DLookup( "[SSN]", "TEMPLATES" , "[SSN] = '" & Me!SSN &
"'")) Then
Forms("EFORMS") .Visible = False
Else
If IsNull(DLookup( "[SSN]", "TEMPLATES" , "[SSN] = '" & Me!SSN & "'"))
Then
DoCmd.OpenQuery ("Appendtemplat es")
End If
End If

If Not IsNull(DLookup( "[SSN]", "195", "[SSN] = '" & Me!SSN & "'")) Then
Forms("EFORMS") .Visible = False
Else
If IsNull(DLookup( "[SSN]", "195", "[SSN] = '" & Me!SSN & "'")) Then
DoCmd.OpenQuery ("Append195" )
End If
End If

If Not IsNull(DLookup( "[SSN]", "795", "[SSN] = '" & Me!SSN & "'")) Then
Forms("EFORMS") .Visible = False
Else
If IsNull(DLookup( "[SSN]", "795", "[SSN] = '" & Me!SSN & "'")) Then
DoCmd.OpenQuery ("Append795" )
End If
End If

If Not IsNull(DLookup( "[SSN]", "21", "[SSN] = '" & Me!SSN & "'")) Then
Forms("EFORMS") .Visible = False
Else
If IsNull(DLookup( "[SSN]", "21", "[SSN] = '" & Me!SSN & "'")) Then
DoCmd.OpenQuery ("Appendssa21ta x")

End If
End If
Forms!eforms.ls tPreInterview.V alue = Null
DoCmd.Close
DoCmd.OpenForm ("Eforms")
DoCmd.RunMacro ("CloseEform s")
DoCmd.OpenForm ("Eforms")

End Sub

What I need is to add this code to a module, and make it run using a
manu bar (I assume via macro). Thanks.

Aug 28 '06 #5

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

Similar topics

2
1734
by: Marcus Schneider | last post by:
I use PythonWin on WinXP. Every time I change a module, I have to leave PythonWin and re enter to make it notice I have made changes. I guess this is not the normal way to do that.. do I have to store the module at a specific place? Is there a kind of "reset" command to make the main module update specific data?
2
4459
by: Marc Shapiro | last post by:
I am relatively new to python (I have used it on and off for a few small projects over the last few years) so I imagine that what I am trying to do has already been done, but practical experience, even if it is reinventing the wheel, is still useful, so... I am trying to write a module to handle drop down menus using curses (on linux). Curses seems to have a wrapper for the panels library, but not forms, or menus. I am not even sure...
1
6700
by: ulf | last post by:
Hello, After I got a FileNotFoundException in my real life CSharp code, I nailed it down to the following line: System.EnterpriseServices.ResourcePool rp = new System.EnterpriseServices.ResourcePool(null); The exception I get for this line is System.IO.FileNotFoundException: The specified module could not be found.
0
1827
by: Edward | last post by:
Access 2k FE/BE My application allows users to enter employee hours against rotas (i.e. who is rostered on, and when). They further want a function to output a report showing the number of hours that each employee is rostered, and to be able to do this for any week. To this end there is a control on the "Rota" form which shows the "Week Commencing", with "Next >" and "< Previous" buttons.
1
4782
by: THDWWSIJQUOK | last post by:
I have (or should I say "had") a module which I invested quite a few hours of work into. I was poking around trying to rename the module and instead wound up removing the darn thing. It's been a long time since I've lost any work because I normally make backups and have the experience not to make stupid mistakes like this. I'm still shocked how quickly it happened... I noticed the module was called "module1" so I went to give it a
7
1950
by: allyn44 | last post by:
Hello--I have the code below attached to a command button--it opens an error log form: DoCmd.OpenForm "ReportError" Forms!reporterror!RecordID = Me!RecID Forms!reporterror!PatientID = Me!PatId End Sub I want to use this on many forms but cannot use a standard module without referencing the form I am pulling the value from--which
3
1207
by: Henry Wu | last post by:
Hi, I have a MDIForm with a menu name mnuVideo that opens a childForm. My question is a newbie question, I was wondering how can I manipulate the mnuVideo that is in the MDIForm from the childForm? Like "enabled" & "checked" properties. Lastly I need to do the same manipulation of the mnuVideo from a Module. Code samples would be very much appreciated.
6
1434
by: Shane Saunders | last post by:
I have a menu option that loads a form and displays infomation. if you go to main form and try to load something else from that same menu, it does a check to see if the form in exist and then reloads it has to or does messagebox. the problem i have is that i want to set the module instance varible to nothing when i exit the form that is being check. The code i am use is If frmWeatherMap Is Nothing Then
1
10066
by: bobano | last post by:
Hi everyone, I am writing a POP3 Client program in Perl. You connect to a POP3 Server and have a running conversation with the mail server using commands from the RFC 1939 Post Office Protocol. This program can perform 5 options from a menu on your POP3 mail by logging in with the correct POP3 server along with a user name and password that you use to log in to your ISP. The user name and password as well as the server name are all hard-coded...
0
8944
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8773
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9180
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6733
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6030
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3259
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.