Re: Kick Starting AfterUpdate Event in another Form

From: TC (no_at_email.here)
Date: 04/29/04


Date: Thu, 29 Apr 2004 12:17:11 +0930

Pete, if you want to call a procedure or function within a form module from
"outside", you must declare the procedure or function Public:

form #1's module:

       PUBLIC sub do_stuff
       msgbox "in do_stuff!"
       end sub

then from some other form:

       forms("... the form name ...").do_stuff

But generally it is not good practice to do that. If two forms call the same
procedure, it is best to declare that procedure in a module on the Modules
table. Declare it Public, as above. Then either form (or any other sub or
function in any module) can call it just by saying: do_stuff.

If it needs to know values from the calling form, just pass those values as
parameters:

declaration of do_stuff in a Module:

        Public do_stuff (Blah as Integer)
        msgbox "do_stuff! " & Blah
        end

calling do_stuff from within a form module, passing the integer value from
control txtBlah:

        do_stuff me![txtBlah]

HTH,
TC

"Pete Halfacree" <anonymous@discussions.microsoft.com> wrote in message
news:535101c42cf9$182e68b0$a401280a@phx.gbl...
> TC, Thank you for your prompt response.
>
> Calling the Sub your way can only be done within the form
> having the Event Procedure and this how I have called up
> the Event (based on the GotFocus Event of the Control
> stimulated by the Enter + Back Tab).
>
> I have tried to Run the procedure from the Calendar form
> using:
> Run frm.ActiveControl.Name & "_AfterUpdate [Event
> Procedure]".
> Access tells me it can't find the procedure.
>
> I have also tried Run frm.name & "." &
> frm.ActiveControl.Name & "_AfterUpdate" and still no joy.
>
> Surely there must be a way!
>
> Regards, Pete
> >-----Original Message-----
> >If a control has an event (including but not limited to
> AfterUpdate) - say:
> >
> > private sub ctl_AfterUpdate()
> >
> >you can invoke that event procedure manually, just like
> any other procedure:
> >
> > msgbox "calling.."
> > ctl_AfterUpdate
> > msgbox "called!"
> >
> >From a code structure viewpoint, it may be better to put
> the common code in
> >a seperate procedure:
> >
> > private sub ctl_AfterUpdate()
> > do_stuff
> > end stuff
> >
> > msgbox "calling.."
> > do_stuff
> > msgbox "called!"
> >
> > private do_stuff()
> > ...
> > end sub
> >
> >Now, if you need to add something extra for the
> AfterUpdate case, but not
> >for the "called programatically" case, you can do that
> easily.
> >
> >HTH,
> >TC
>



Relevant Pages

  • Re: Graying out control not working
    ... Is it Best Practice to declare a variable, and, if so, would it be declared ... appears w/ the other Event Procedure code tied to this particular form. ... "Sandra Daigle" wrote: ... > Explicit" in the module header your code is comparing the combo to the ...
    (microsoft.public.access.formscoding)
  • Re: Kick Starting AfterUpdate Event in another Form
    ... "Pete Halfacree" wrote in message ... although I will have to analyse my Process again. ... Declare>it< Public ..." ... >> end sub ...
    (microsoft.public.access.formscoding)
  • Re: Proper way to return a string
    ... the length is declared in the calling program - *NOT* determined by ... I'm too tired to check right now, but an internal function with a len=* ... You are required to declare the ... length in the calling scope. ...
    (comp.lang.fortran)
  • Re: some people "think"...
    ... commentators make their living announcing TODAY's tennis. ... he has something pete didn't - +1 FO, ... I do not think the United States would come to an end if ... we lost our power to declare an Act of Congress void. ...
    (rec.sport.tennis)
  • Re: Variable scope mystery
    ... inside nested function even while you are calling it in. ... so I declare it having a global scope. ... > can't be accessed within blahblah(). ... > global $foo; ...
    (comp.lang.php)