473,326 Members | 2,048 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,326 software developers and data experts.

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
7 1931
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Robin Cull | last post by:
Hi all, I'm writing a script that needs to do lookups on the UNIX passwd and groups file on textual usernames/group names and return numeric UID/GID. Something that gives access to the C...
5
by: sdhyok | last post by:
Here is my situation. To add more functionalities to a standard library(datetime) in python, I am implementing my own code called vp.datetime (directory structure, vp/datetime.py). To make it...
3
by: Laax | last post by:
Hi, I am trying to compile a .cc file and get the following error. I have translated the error message from original japanese text. So, it may not look exactly like standard(English) error...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
8
by: Andreas Klemt | last post by:
Hello, I get this error Message "cannot redirect after http headers have been sent" when I do this response.redirect ("home.aspx") How can I find out with vb.net if already a http header has...
3
by: David T. Ashley | last post by:
Hi, Red Hat Enterprise Linux 4.X. I'm writing command-line PHP scripts for the first time. I get the messages below. What do they mean? Are these operating system library modules, or...
21
by: Cottonwood | last post by:
I want to call a C module from a Fortran program. Whatever I tried - the linker could not find the C module. I know about the leading underscore and switched even that off. I abstracted everything...
2
by: Chris Miles | last post by:
On a standard Solaris 10 installation with Sun-supplied open-source packages installed (like SFWrline for readline libs) I cannot seem to force Python configure/setup.py to build with readline...
1
by: kw.housing | last post by:
I have all the library already in path: $ ls -l /opt/IBM/db2/lib64 | grep libdb2o -r-xr-xr-x 1 bin bin 7757295 Jul 12 2006 libdb2osse.a* -r--r--r-- 1 bin bin ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...

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.