How to utilise "Me" in a public function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Keith

    How to utilise "Me" in a public function

    A2003, XP Pro.

    I have a VBA routine that I use to record data transactions in a history
    table. I'd like to use this routine for every form in my app by putting it
    in a public function and calling it from each form. Trouble is, the code
    uses the "Me" keyword throughout to refer to data objects and I can't quite
    fathom out how to pass it to my function and how to handle it once it's
    there.

    Any pointers?

    Many thanks.
    Keith.


  • Keith

    #2
    Re: How to utilise "Me&quo t; in a public function

    "Keith" <keith.wilby@ba eAWAYWITHITsyst ems.com> wrote in message
    news:42ca3b1f$1 _1@glkas0286.gr eenlnk.net...[color=blue]
    > A2003, XP Pro.
    >
    > I have a VBA routine that I use to record data transactions in a history
    > table. I'd like to use this routine for every form in my app by putting
    > it in a public function and calling it from each form. Trouble is, the
    > code uses the "Me" keyword throughout to refer to data objects and I can't
    > quite fathom out how to pass it to my function and how to handle it once
    > it's there.
    >[/color]
    Doesn't matter, sussed it. If anyone's interested, you pass the "Me"
    keyword to a "Form" object in the function. Hope that makes sense :o)


    Comment

    • MLH

      #3
      Re: How to utilise &quot;Me&quo t; in a public function

      You could pass the formname to the function on each call.
      I realize that would mean modifying the call to your public
      procedure on each and every form that calls it, but its sure
      to work.

      Comment

      • David W. Fenton

        #4
        Re: How to utilise &quot;Me&quo t; in a public function

        MLH <CRCI@NorthStat e.net> wrote in
        news:ur3lc1lr1o sphmp8j9r0c1jhe bt63uuab6@4ax.c om:
        [color=blue]
        > You could pass the formname to the function on each call.
        > I realize that would mean modifying the call to your public
        > procedure on each and every form that calls it, but its sure
        > to work.[/color]

        That's not the best solution, as you'd then have to look up the form
        in the forms collection.

        The best solution is to pass a form reference as a parameter of your
        subroutine:

        Public Sub DoSomething(frm As Form)
        Set frm.Visible = True
        [etc.]
        End Sub

        And you'd call it in any form like this:

        Call DoSomething(Me)

        That passes (By Reference) a pointer to the original form instance.
        Passing the name would then require a lookup, and that's
        inefficient.

        Also, doing it with passing the form reference means that "Me" in
        your subroutine can simply be replaced with "frm", whereas you'd
        still have to set up some kind of object within the subroutine if
        passing the form name (though you could do a WITH block, if it
        worked for the code you had there).

        --
        David W. Fenton http://www.bway.net/~dfenton
        dfenton at bway dot net http://www.bway.net/~dfassoc

        Comment

        • Keith

          #5
          Re: How to utilise &quot;Me&quo t; in a public function

          "David W. Fenton" <dXXXfenton@bwa y.net.invalid> wrote in message
          news:Xns968AA30 EF1E59dfentonbw aynetinvali@24. 168.128.90...[color=blue]
          >
          > The best solution is to pass a form reference as a parameter of your
          > subroutine:
          >
          > Public Sub DoSomething(frm As Form)
          > Set frm.Visible = True
          > [etc.]
          > End Sub
          >
          > And you'd call it in any form like this:
          >
          > Call DoSomething(Me)
          >[/color]
          That's exactly what I have done David, I managed to suss it out about an
          hour after the OP.


          Comment

          Working...