Passing a value from one form to another

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ferg96
    New Member
    • Jul 2007
    • 4

    Passing a value from one form to another

    I have a main form which displays various text etc depending on the file number eg, DA314, DA315.
    On the main form I have a button that opens up another form with a textbox in it. I want this text box to display the text that applies to that file number. Currently it opens on the first file and not the file that the form was opened from.

    Any help please?
  • MGrowneyARSI
    New Member
    • Aug 2007
    • 90

    #2
    Chose a field from the first form that is a unique identifier put this on the second form in the query for the second form for the U.I. put = Forms!The First Forms Name!The Name of the U.I. Then the second form should only be allowed to see the text that relates to the current record on the main form

    Comment

    • ferg96
      New Member
      • Jul 2007
      • 4

      #3
      I am not sure what you mean. Where exactly do I put the code?

      Thanks for the quick response

      Comment

      • MGrowneyARSI
        New Member
        • Aug 2007
        • 90

        #4
        Ok from the strat you had to build tables and you must have made a primary Key this would be a unique identifier. Then I sure you created querys to biuld your forms off of if not make sure u do it would be in the critiria of the query that you would put the code this limits the query so that it only sees records where the Key field matches the key field on your main form. let me know if you need any more help

        Comment

        • RobH
          New Member
          • Jul 2007
          • 56

          #5
          If this second form is only executed from the first form then you could even add to the "On Open" in Events the following

          Code:
          Me.TextBoxOn2ndForm = [Forms]![TextBoxOn1stForm]
          If the 2nd form is tied to a query then you could use the "Where" filter pass this is ideal for use with forms designed to gain search parameters for the next form.

          On the first form when you do the

          DoCmd.OpenForm "2ndForm"

          You can add to it the options that apply a filter however if the Filter is complicated you should set the filter to a variable first.
          the below allows for text before and after the Textbox entry - if you want a strick match then replace the Like with an = and remove the '* and *' from the strWhere line

          Code:
          strWhere = "(((RecordNum) Like '*" & Me!TextBoxOn1stForm & "*')))"
              DoCmd.OpenForm "2ndForm", , , strWhere

          Comment

          • ferg96
            New Member
            • Jul 2007
            • 4

            #6
            Finally got it to work.

            Thanks for your help!

            Comment

            Working...