467,894 Members | 1,491 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,894 developers. It's quick & easy.

Cannot use a standard module

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
defeats my purpose. Is there any other way to use this code in
multiple places?

thanks
bob
Nov 13 '05 #1
  • viewed: 1769
Share:
7 Replies
Yes, you can move the code to a stadnare module. The code will look like:
dim frmMe as form

set frmMe = screen.ActiveForm

DoCmd.OpenForm "ReportError"
Forms!reporterror!RecordID = frmMe!RecID
Forms!reporterror!PatientID = frmMe!PatId
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.members.shaw.ca/AlbertKallal
Nov 13 '05 #2
Thank you very much! Works just fine!!
On Tue, 22 Mar 2005 21:43:46 GMT, "Albert D. Kallal" <ka****@msn.com>
wrote:
Yes, you can move the code to a stadnare module. The code will look like:
dim frmMe as form

set frmMe = screen.ActiveForm

DoCmd.OpenForm "ReportError"
Forms!reporterror!RecordID = frmMe!RecID
Forms!reporterror!PatientID = frmMe!PatId


Nov 13 '05 #3
And as long as I am asking--can I pull the originating form name into
a field on the error form also?

thanks
On Tue, 22 Mar 2005 15:00:36 -0700, al*****@cox.net wrote:
Thank you very much! Works just fine!!
On Tue, 22 Mar 2005 21:43:46 GMT, "Albert D. Kallal" <ka****@msn.com>
wrote:
Yes, you can move the code to a stadnare module. The code will look like:
dim frmMe as form

set frmMe = screen.ActiveForm

DoCmd.OpenForm "ReportError"
Forms!reporterror!RecordID = frmMe!RecID
Forms!reporterror!PatientID = frmMe!PatId


Nov 13 '05 #4
frmMe.Name

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

<al*****@cox.net> wrote in message
news:6e********************************@4ax.com...
And as long as I am asking--can I pull the originating form name into
a field on the error form also?

thanks
On Tue, 22 Mar 2005 15:00:36 -0700, al*****@cox.net wrote:
Thank you very much! Works just fine!!
On Tue, 22 Mar 2005 21:43:46 GMT, "Albert D. Kallal" <ka****@msn.com>
wrote:
Yes, you can move the code to a stadnare module. The code will look like:
dim frmMe as form

set frmMe = screen.ActiveForm

DoCmd.OpenForm "ReportError"
Forms!reporterror!RecordID = frmMe!RecID
Forms!reporterror!PatientID = frmMe!PatId

Nov 13 '05 #5
"Albert D. Kallal" <ka****@msn.com> wrote in
news:mk00e.759333$6l.335837@pd7tw2no:
Yes, you can move the code to a stadnare module. The code will
look like:
dim frmMe as form

set frmMe = screen.ActiveForm

DoCmd.OpenForm "ReportError"
Forms!reporterror!RecordID = frmMe!RecID
Forms!reporterror!PatientID = frmMe!PatId


Why not make the form name an argument passed to the subroutine?

Public Sub OpenErrorForm(frm As Form)
DoCmd.OpenForm "ReportError"
With Forms!ReportError
!RecordID = frm!RecID
!PatientID = frm!PatId
End With
End Sub

You'd use it like this:

Call OpenErrorForm (Me)

OR

OpenErrorForm Me

By passing the form, you don't have to worry about assigning the
variable and you get the benefit of calling it for something other
than the currently active form (should you ever need to).

I also have never trusted .ActiveForm, as it depends on events in
the UI. Passing the exact form reference seems to me to be the most
robust way of doing this, rather than depending on a 2nd-hand method
of finding out which form it is.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #6
"David W. Fenton" <dX********@bway.net.invalid> wrote in message
news:Xn**********************************@24.168.1 28.78...
By passing the form, you don't have to worry about assigning the
variable and you get the benefit of calling it for something other
than the currently active form (should you ever need to).

Yes, the above is a fair point.

I also have never trusted .ActiveForm, as it depends on events in
the UI. Passing the exact form reference seems to me to be the most
robust way of doing this, rather than depending on a 2nd-hand method
of finding out which form it is.


The above has never been a problem Remember, when you start using a LOT of
custom menu bars etc, then your code OFTEN has to rely the screen object.
Further, this approach also means that ones custom menu bars/code will
operation on any active form. And, no matter what code calls the routine..it
will work, and those calling routines don't have to care/worry about passing
the form object. (so, there is some pros/cons here!).

So, I 100% agree, for most code, I would in fact pass the form object.
However, for menu bar code..and "general" routines (that menus + tool bars
force you to write!!), then using the screen object is standard fair, and is
reliable. The end result is more general code. You do as a rule need to
pick up the screen object RIGHT AT the start of the code, since any focus
change could have disaster results. However, once you pick up the screen
object, then a focus change does not cause a problem. Ones mileage will
certainly vary on this...especially if one is not a big user of menu bars
(which I am!).

In applications built around custom menus......often the screen object is
the only reasonable approach.

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.members.shaw.ca/AlbertKallal
Nov 13 '05 #7
Thanks to David and Albert--I have a need for this module in many
different areas of projects I am working on and this will save me lots
of time! Now to figure out loops!
On Wed, 23 Mar 2005 00:55:38 GMT, "David W. Fenton"
<dX********@bway.net.invalid> wrote:
"Albert D. Kallal" <ka****@msn.com> wrote in
news:mk00e.759333$6l.335837@pd7tw2no:
Yes, you can move the code to a stadnare module. The code will
look like:
dim frmMe as form

set frmMe = screen.ActiveForm

DoCmd.OpenForm "ReportError"
Forms!reporterror!RecordID = frmMe!RecID
Forms!reporterror!PatientID = frmMe!PatId


Why not make the form name an argument passed to the subroutine?

Public Sub OpenErrorForm(frm As Form)
DoCmd.OpenForm "ReportError"
With Forms!ReportError
!RecordID = frm!RecID
!PatientID = frm!PatId
End With
End Sub

You'd use it like this:

Call OpenErrorForm (Me)

OR

OpenErrorForm Me

By passing the form, you don't have to worry about assigning the
variable and you get the benefit of calling it for something other
than the currently active form (should you ever need to).

I also have never trusted .ActiveForm, as it depends on events in
the UI. Passing the exact form reference seems to me to be the most
robust way of doing this, rather than depending on a 2nd-hand method
of finding out which form it is.


Nov 13 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Andreas Klemt | last post: by
3 posts views Thread by David T. Ashley | last post: by
21 posts views Thread by Cottonwood | last post: by
1 post views Thread by kw.housing | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.