By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,921 Members | 1,479 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,921 IT Pros & Developers. It's quick & easy.

Creating a Module

P: n/a
I have code that is currently placed in the OnClose Event, and it's duplicated
in multiple forms, I would like to convert it to a module and call that module
instead of copy and pasting the code. Here is the code:

If IsNull(Forms!frm1!FormHolder) Then
DoCmd.OpenForm "Switchboard"
Else
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = Forms!frm1!FormHolder
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Thank you in advance for your assistance. Frm1 is open all the time in a Hidden
mode.

Michael
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Create a new Module and type enter the code below and save module. Then use
the OnClose event to call your module using "Call functionname()" (Be sure
to call the function name and not the name of the module that you saved.

Public Function functionname()
If IsNull(Forms!frm1!FormHolder) Then
DoCmd.OpenForm "Switchboard"
Else
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = Forms!frm1!FormHolder
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
End Function

"Lumpierbritches" <lu*************@aol.com> wrote in message
news:20***************************@mb-m11.aol.com...
I have code that is currently placed in the OnClose Event, and it's duplicated in multiple forms, I would like to convert it to a module and call that module instead of copy and pasting the code. Here is the code:

If IsNull(Forms!frm1!FormHolder) Then
DoCmd.OpenForm "Switchboard"
Else
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = Forms!frm1!FormHolder
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Thank you in advance for your assistance. Frm1 is open all the time in a Hidden mode.

Michael

Nov 13 '05 #2

P: n/a
You'll still need the onclose event of your form, just insted of the
below code in it, you'll just make a function call insted. Place the
below code in a function, in a module, and in the onclose event, just
call the function from your module just as you would call any other
function.

Also, I understand the variable defining, but it has always been my
own personal opinion that if you never use a variable, you can get rid
of it entirely (stLinkCriteria) and if you're only using it once, you
don't really need it either (stdocname). Defining two unnecessary
variables may not seem like a lot, but spread out over many forms used
repeatedly, it is a waste of memory. Getting rid of unnecessary
variables is an easy way to make your program run slightly faster and
use less memory. Again, just my personal opinion - take it however
you want.

lu*************@aol.com (Lumpierbritches) wrote in message news:<20***************************@mb-m11.aol.com>...
I have code that is currently placed in the OnClose Event, and it's duplicated
in multiple forms, I would like to convert it to a module and call that module
instead of copy and pasting the code. Here is the code:

If IsNull(Forms!frm1!FormHolder) Then
DoCmd.OpenForm "Switchboard"
Else
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = Forms!frm1!FormHolder
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Thank you in advance for your assistance. Frm1 is open all the time in a Hidden
mode.

Michael

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.