Assigning Openargs to a "Form" Variable!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Barry Edmund Wright

    Assigning Openargs to a "Form" Variable!

    Hi All,

    I am using the code below to assign a form name to a form variable (vFrm).
    Is there a way to assign the Openargs string directly to vFrm, i.e. vFrm =
    Openargs ?

    Private Sub Form_Load()
    Public vFrm As Form

    If Openargs = "subfrmProjects " then
    vFrm = Form_subfrmProj ects
    ElseIf Openargs = "frmProject s" Then
    Set vFrm = Form_frmProject s
    ElseIf Openargs = "frmCompone nts" Then
    Set vFrm = Form_frmCompone nts
    End If

    End Sub

    Thanks for your assistance,
    Barry


  • MGFoster

    #2
    Re: Assigning Openargs to a "Form&quot ; Variable!

    Barry Edmund Wright wrote:[color=blue]
    > Hi All,
    >
    > I am using the code below to assign a form name to a form variable (vFrm).
    > Is there a way to assign the Openargs string directly to vFrm, i.e. vFrm =
    > Openargs ?
    >
    > Private Sub Form_Load()
    > Public vFrm As Form
    >
    > If Openargs = "subfrmProjects " then
    > vFrm = Form_subfrmProj ects
    > ElseIf Openargs = "frmProject s" Then
    > Set vFrm = Form_frmProject s
    > ElseIf Openargs = "frmCompone nts" Then
    > Set vFrm = Form_frmCompone nts
    > End If
    >
    > End Sub[/color]

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    You could do something like this:

    -- Declaration section

    ' Declare a module level variable to hold the name of the
    ' calling form.
    Dim m_strCallingFor m As String

    ' An object reference variable that will hold the reference
    ' to the calling form object.
    Dim m_frm As Form

    Private Sub Form_Load()

    m_strCallingFor m = Me.OpenArgs

    End Sub

    ' Where you need to set a form object variable to the calling form
    ' do this.

    Set m_frm = Forms(m_strCall ingForm)

    This is what's known as "late binding." What you had been doing is
    "early binding." Early binding is usually the preferred binding option
    'cuz the compiler does all the binding of object methods/events before
    the program runs. Late binding means the binding is done during the
    program run and this can, possibly, slow down the processing. I've
    found late binding to work well on most things I use it for. YMMV.
    --
    MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
    Oakland, CA (USA)

    -----BEGIN PGP SIGNATURE-----
    Version: PGP for Personal Privacy 5.0
    Charset: noconv

    iQA/AwUBQmPw+oechKq OuFEgEQLaKgCgnI 39gRGBttv+b5ZGJ m0383awyWgAnR2I
    WuPYyljBBjrtcJd QCDxa/UJM
    =G1Tc
    -----END PGP SIGNATURE-----

    Comment

    • Barry Edmund Wright

      #3
      Re: Assigning Openargs to a &quot;Form&quot ; Variable!

      MG, that worked like a charm! And thanks for taking the time to expain about
      the late-binding thingy!

      Best regards,
      Barry

      "MGFoster" <me@privacy.com > wrote in message
      news:QhS8e.1026 5$lP1.8731@news read1.news.pas. earthlink.net.. .[color=blue]
      > Barry Edmund Wright wrote:[color=green]
      >> Hi All,
      >>
      >> I am using the code below to assign a form name to a form variable
      >> (vFrm).
      >> Is there a way to assign the Openargs string directly to vFrm, i.e. vFrm
      >> = Openargs ?
      >>
      >> Private Sub Form_Load()
      >> Public vFrm As Form
      >>
      >> If Openargs = "subfrmProjects " then
      >> vFrm = Form_subfrmProj ects
      >> ElseIf Openargs = "frmProject s" Then
      >> Set vFrm = Form_frmProject s
      >> ElseIf Openargs = "frmCompone nts" Then
      >> Set vFrm = Form_frmCompone nts
      >> End If
      >>
      >> End Sub[/color]
      >
      > -----BEGIN PGP SIGNED MESSAGE-----
      > Hash: SHA1
      >
      > You could do something like this:
      >
      > -- Declaration section
      >
      > ' Declare a module level variable to hold the name of the
      > ' calling form.
      > Dim m_strCallingFor m As String
      >
      > ' An object reference variable that will hold the reference
      > ' to the calling form object.
      > Dim m_frm As Form
      >
      > Private Sub Form_Load()
      >
      > m_strCallingFor m = Me.OpenArgs
      >
      > End Sub
      >
      > ' Where you need to set a form object variable to the calling form
      > ' do this.
      >
      > Set m_frm = Forms(m_strCall ingForm)
      >
      > This is what's known as "late binding." What you had been doing is
      > "early binding." Early binding is usually the preferred binding option
      > 'cuz the compiler does all the binding of object methods/events before
      > the program runs. Late binding means the binding is done during the
      > program run and this can, possibly, slow down the processing. I've
      > found late binding to work well on most things I use it for. YMMV.
      > --
      > MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
      > Oakland, CA (USA)
      >
      > -----BEGIN PGP SIGNATURE-----
      > Version: PGP for Personal Privacy 5.0
      > Charset: noconv
      >
      > iQA/AwUBQmPw+oechKq OuFEgEQLaKgCgnI 39gRGBttv+b5ZGJ m0383awyWgAnR2I
      > WuPYyljBBjrtcJd QCDxa/UJM
      > =G1Tc
      > -----END PGP SIGNATURE-----[/color]


      Comment

      • Barry Edmund Wright

        #4
        Oops! I jumped the gun!

        Sorry MG, I hadn't cleared out some of the old code, so the module wasn't
        using new code.

        When I try to assign the global string:

        Set m_frm = Forms(m_strCall ingForm)

        I get run-time error '2450'
        Database cannot find the form 'subfrmComp1' referred to in a macro
        expression or Visual Basic code.

        That's basically the problem I always get: I don't know how to assign a
        "string" variable to a form using the Set statement.

        Any thoughts on how to correct this error?
        Thanks, Barry

        "MGFoster" <me@privacy.com > wrote in message
        news:QhS8e.1026 5$lP1.8731@news read1.news.pas. earthlink.net.. .[color=blue]
        > Barry Edmund Wright wrote:[color=green]
        >> Hi All,
        >>
        >> I am using the code below to assign a form name to a form variable
        >> (vFrm).
        >> Is there a way to assign the Openargs string directly to vFrm, i.e. vFrm
        >> = Openargs ?
        >>
        >> Private Sub Form_Load()
        >> Public vFrm As Form
        >>
        >> If Openargs = "subfrmProjects " then
        >> vFrm = Form_subfrmProj ects
        >> ElseIf Openargs = "frmProject s" Then
        >> Set vFrm = Form_frmProject s
        >> ElseIf Openargs = "frmCompone nts" Then
        >> Set vFrm = Form_frmCompone nts
        >> End If
        >>
        >> End Sub[/color]
        >
        > -----BEGIN PGP SIGNED MESSAGE-----
        > Hash: SHA1
        >
        > You could do something like this:
        >
        > -- Declaration section
        >
        > ' Declare a module level variable to hold the name of the
        > ' calling form.
        > Dim m_strCallingFor m As String
        >
        > ' An object reference variable that will hold the reference
        > ' to the calling form object.
        > Dim m_frm As Form
        >
        > Private Sub Form_Load()
        >
        > m_strCallingFor m = Me.OpenArgs
        >
        > End Sub
        >
        > ' Where you need to set a form object variable to the calling form
        > ' do this.
        >
        > Set m_frm = Forms(m_strCall ingForm)
        >
        > This is what's known as "late binding." What you had been doing is
        > "early binding." Early binding is usually the preferred binding option
        > 'cuz the compiler does all the binding of object methods/events before
        > the program runs. Late binding means the binding is done during the
        > program run and this can, possibly, slow down the processing. I've
        > found late binding to work well on most things I use it for. YMMV.
        > --
        > MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
        > Oakland, CA (USA)
        >
        > -----BEGIN PGP SIGNATURE-----
        > Version: PGP for Personal Privacy 5.0
        > Charset: noconv
        >
        > iQA/AwUBQmPw+oechKq OuFEgEQLaKgCgnI 39gRGBttv+b5ZGJ m0383awyWgAnR2I
        > WuPYyljBBjrtcJd QCDxa/UJM
        > =G1Tc
        > -----END PGP SIGNATURE-----[/color]


        Comment

        • MGFoster

          #5
          Re: Oops! I jumped the gun!

          -----BEGIN PGP SIGNED MESSAGE-----
          Hash: SHA1

          By the name of the form "subfrmComp 1" I'm guessing that the form is
          being used as a subform, correct? If so, you can't use my example to
          set the m_frm variable to the name of the form when it is a subform in
          another form. To set a form reference variable to a subform you have to
          indicate where that subform is (in which form). E.g.:

          Set m_frm = Forms(m_strCall ingForm)!subFor mName.Form

          If the subform is a subform of a subform (nested 2 deep):

          Set m_frm = Forms(m_strCall ingForm)!subFor m1Name!subForm2 Name.Form

          You can refer to subforms this way, too:

          Set m_frm = Forms("form_nam e")("subform_na me").Form

          So if you could pass the calling main form name and its subform name in
          the OpenArgs parameter (and parse them out) you could use the above
          example to set the m_frm variable.

          See the Access VBA Help article "Form Object." Open the Debug window
          [Ctrl+G] and type in Forms, put the cursor on the word Forms & hit the
          F1 key. Then click on the Form bar (bottom blue bar in the diagram at
          the top of the Help page). At the bottom of the "Form Object" Help page
          is a discussion of subforms & how to refer to them using VBA.
          --
          MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
          Oakland, CA (USA)

          -----BEGIN PGP SIGNATURE-----
          Version: PGP for Personal Privacy 5.0
          Charset: noconv

          iQA/AwUBQmUvaIechKq OuFEgEQIw8gCg8E FBZFNKM16J5uGsX x4gzLL1mvUAn0j/
          7WX8YL2ld9CIfSB 75/OOOVZv
          =1xhm
          -----END PGP SIGNATURE-----

          Barry Edmund Wright wrote:[color=blue]
          > Sorry MG, I hadn't cleared out some of the old code, so the module wasn't
          > using new code.
          >
          > When I try to assign the global string:
          >
          > Set m_frm = Forms(m_strCall ingForm)
          >
          > I get run-time error '2450'
          > Database cannot find the form 'subfrmComp1' referred to in a macro
          > expression or Visual Basic code.
          >
          > That's basically the problem I always get: I don't know how to assign a
          > "string" variable to a form using the Set statement.
          >
          > Any thoughts on how to correct this error?
          > Thanks, Barry
          >
          > "MGFoster" <me@privacy.com > wrote in message
          > news:QhS8e.1026 5$lP1.8731@news read1.news.pas. earthlink.net.. .
          >[color=green]
          >>Barry Edmund Wright wrote:
          >>[color=darkred]
          >>>Hi All,
          >>>
          >>>I am using the code below to assign a form name to a form variable
          >>>(vFrm).
          >>>Is there a way to assign the Openargs string directly to vFrm, i.e. vFrm
          >>>= Openargs ?
          >>>
          >>>Private Sub Form_Load()
          >>> Public vFrm As Form
          >>>
          >>> If Openargs = "subfrmProjects " then
          >>> vFrm = Form_subfrmProj ects
          >>> ElseIf Openargs = "frmProject s" Then
          >>> Set vFrm = Form_frmProject s
          >>> ElseIf Openargs = "frmCompone nts" Then
          >>> Set vFrm = Form_frmCompone nts
          >>> End If
          >>>
          >>>End Sub[/color]
          >>
          >>-----BEGIN PGP SIGNED MESSAGE-----
          >>Hash: SHA1
          >>
          >>You could do something like this:
          >>
          >> -- Declaration section
          >>
          >>' Declare a module level variable to hold the name of the
          >>' calling form.
          >>Dim m_strCallingFor m As String
          >>
          >>' An object reference variable that will hold the reference
          >>' to the calling form object.
          >>Dim m_frm As Form
          >>
          >>Private Sub Form_Load()
          >>
          >> m_strCallingFor m = Me.OpenArgs
          >>
          >>End Sub
          >>
          >>' Where you need to set a form object variable to the calling form
          >>' do this.
          >>
          >>Set m_frm = Forms(m_strCall ingForm)
          >>
          >>This is what's known as "late binding." What you had been doing is
          >>"early binding." Early binding is usually the preferred binding option
          >>'cuz the compiler does all the binding of object methods/events before
          >>the program runs. Late binding means the binding is done during the
          >>program run and this can, possibly, slow down the processing. I've
          >>found late binding to work well on most things I use it for. YMMV.
          >>--
          >>MGFoster:::mg f00 <at> earthlink <decimal-point> net
          >>Oakland, CA (USA)
          >>
          >>-----BEGIN PGP SIGNATURE-----
          >>Version: PGP for Personal Privacy 5.0
          >>Charset: noconv
          >>
          >>iQA/AwUBQmPw+oechKq OuFEgEQLaKgCgnI 39gRGBttv+b5ZGJ m0383awyWgAnR2I
          >>WuPYyljBBjrtc JdQCDxa/UJM
          >>=G1Tc
          >>-----END PGP SIGNATURE-----[/color]
          >
          >
          >[/color]

          Comment

          Working...