Passing variables between Forms

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • salzan
    New Member
    • Feb 2008
    • 38

    Passing variables between Forms

    is there a way to pass variables between forms? for example have one form calling another one and passing a value to it.
    Thanks for your help.
    Salzan
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    If both forms are open then you can reference a control on formA from formB as follows:

    Forms![formA]![ControlName]

    Comment

    • salzan
      New Member
      • Feb 2008
      • 38

      #3
      Thank you............ ............... .....

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        Another way would be to use OpenArgs.

        From you first form:
        [CODE=vb]DoCmd.OpenForm "SecondFormName ", , , , , , "ValueToPas s"
        [/CODE]

        In your second form:
        [CODE=vb]Private Sub Form_Load()
        If Len(Nz(Me.OpenA rgs, "")) > 0 Then
        Me.YourControlN ame = Me.OpenArgs
        End If
        End Sub
        [/CODE]

        With Mary's method your first form must stay open until the value's been passed.

        Welcome to TheScripts!

        Linq ;0)>

        Comment

        • MMcCarthy
          Recognized Expert MVP
          • Aug 2006
          • 14387

          #5
          Very true Linq ... :)

          Comment

          • salzan
            New Member
            • Feb 2008
            • 38

            #6
            Originally posted by msquared
            Very true Linq ... :)
            THNAKS A MILLION........

            One more question, I assume I need all the commas to get to openarg, correct?

            Comment

            • missinglinq
              Recognized Expert Specialist
              • Nov 2006
              • 3533

              #7
              Hey, Mary! My ISP's going nuts tonight; you hadn't answered when (20 minutes ago) I clicked "Send!"

              ;0)>

              Comment

              • missinglinq
                Recognized Expert Specialist
                • Nov 2006
                • 3533

                #8
                Yes! They're "place holders" for arguments that aren't being used here. You can omit optional arguments, but if you use an argument that appears to the right of them, you have to include the comma(s) for missing ones.

                Linq ;0)>

                Comment

                • MMcCarthy
                  Recognized Expert MVP
                  • Aug 2006
                  • 14387

                  #9
                  Originally posted by missinglinq
                  Hey, Mary! My ISP's going nuts tonight; you hadn't answered when (20 minutes ago) I clicked "Send!"

                  ;0)>
                  Never a problem, your answer was better than mine anyway.

                  Comment

                  Working...