invoke a form with a button from another

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • trixxnixon
    New Member
    • Sep 2008
    • 98

    invoke a form with a button from another

    is there a way to make a button on a form open another form with the same record and carry over some of the data from the initial form?
  • beacon
    Contributor
    • Aug 2007
    • 579

    #2
    Originally posted by trixxnixon
    is there a way to make a button on a form open another form with the same record and carry over some of the data from the initial form?
    Hi Trixx,

    Let's take this one step at a time. To open a form with a command button add the following VBA code:
    Code:
    Private Sub cmdOpenForm_Click()
    
       'Use the DoCmd to open the form, acNormal is the view the form is opened in
       DoCmd.OpenForm "NextForm", acNormal
    
    End Sub
    If you need to pass parameters, we need to figure out how much data you are trying to pass because there are different methods of doing so.

    For instance, if you need to pass the value of one text box, you VBA would look like this:
    Code:
    Private Sub cmdOpenForm_Click()
    
       'Declare a variable to hold the value of the text box
       Dim myVar
    
       'Set the value of the variable equal to the text box
       myVar = txtAddress.Value
    
       'Now use the OpenForm method and use the variable in the_
           OpenArgs section, which is the 5th comma after acNormal
       DoCmd.OpenForm "NextForm", acNormal, , , , , myVar
    
    End Sub
    Then on the form you are trying to open, I would create an invisible text box called myParameter and then enter the following VBA code:
    Code:
    Private Sub Form_Load()
    
       'Set the myParameter text box equal to OpenArgs
       myParameter.Value = me.OpenArgs
    
       'Then you can set the desired text box equal to myParameter
       txtSecondAddress.value = myParameter.Value
    End Sub
    If you need to pass multiple pieces of data, then you have to put each parameter in OpenArgs, separate each with an ampersand (&) and a semicolon in quotations. Then, once you've passed the OpenArgs, you have to separate each piece of data with the Split() function.

    I'm not going to rewrite it because missingLinq has already done it. Here's a link to the page that helped me out tremendously and changed the way I look at forms. http://bytes.com/topic/access/answer...ue-form1-form2

    Hope this helps

    - beacon

    Comment

    • trixxnixon
      New Member
      • Sep 2008
      • 98

      #3
      Originally posted by beacon
      Hi Trixx,

      Let's take this one step at a time. To open a form with a command button add the following VBA code:
      Code:
      Private Sub cmdOpenForm_Click()
      
         'Use the DoCmd to open the form, acNormal is the view the form is opened in
         DoCmd.OpenForm "NextForm", acNormal
      
      End Sub
      If you need to pass parameters, we need to figure out how much data you are trying to pass because there are different methods of doing so.

      For instance, if you need to pass the value of one text box, you VBA would look like this:
      Code:
      Private Sub cmdOpenForm_Click()
      
         'Declare a variable to hold the value of the text box
         Dim myVar
      
         'Set the value of the variable equal to the text box
         myVar = txtAddress.Value
      
         'Now use the OpenForm method and use the variable in the_
             OpenArgs section, which is the 5th comma after acNormal
         DoCmd.OpenForm "NextForm", acNormal, , , , , myVar
      
      End Sub
      Then on the form you are trying to open, I would create an invisible text box called myParameter and then enter the following VBA code:
      Code:
      Private Sub Form_Load()
      
         'Set the myParameter text box equal to OpenArgs
         myParameter.Value = me.OpenArgs
      
         'Then you can set the desired text box equal to myParameter
         txtSecondAddress.value = myParameter.Value
      End Sub
      If you need to pass multiple pieces of data, then you have to put each parameter in OpenArgs, separate each with an ampersand (&) and a semicolon in quotations. Then, once you've passed the OpenArgs, you have to separate each piece of data with the Split() function.

      I'm not going to rewrite it because missingLinq has already done it. Here's a link to the page that helped me out tremendously and changed the way I look at forms. http://bytes.com/topic/access/answer...ue-form1-form2

      Hope this helps

      - beacon


      i only need to transfer the data from one text box from another, this should help. i am going to try it right now.

      thank you for such a quick responce.

      Comment

      • beacon
        Contributor
        • Aug 2007
        • 579

        #4
        Let me know how it works out.

        If you get this down, you can move on to the step I just recently got to work...reading a parameter from user input on an initial form and then passing it to each subsequent form (including the Switchboard) to ensure that the user only selects data that pertains to them.

        This just involves putting a myParameter invisible text box on each page that should receive the parameter and making sure that the parameter is passed in OpenArgs.

        So, let's say I open the db and the form asks me to select myself from the list. I choose my name, select submit, and I'm taken to the Switchboard and a text box says "Welcome back beacon!" Then I choose to open another form, and in the name field it already has beacon. Using it with DLookup, I could potentially fill in other information that relates to me as long as the parameter is passed successfully.

        Anyway, just some things to try if you get your initial question to work properly.

        - beacon

        Comment

        • trixxnixon
          New Member
          • Sep 2008
          • 98

          #5
          Originally posted by beacon
          Let me know how it works out.

          If you get this down, you can move on to the step I just recently got to work...reading a parameter from user input on an initial form and then passing it to each subsequent form (including the Switchboard) to ensure that the user only selects data that pertains to them.

          This just involves putting a myParameter invisible text box on each page that should receive the parameter and making sure that the parameter is passed in OpenArgs.

          So, let's say I open the db and the form asks me to select myself from the list. I choose my name, select submit, and I'm taken to the Switchboard and a text box says "Welcome back beacon!" Then I choose to open another form, and in the name field it already has beacon. Using it with DLookup, I could potentially fill in other information that relates to me as long as the parameter is passed successfully.

          Anyway, just some things to try if you get your initial question to work properly.

          - beacon


          oh no, i got it to work with no problem, i still dont quite understand the open argument, but i know how to use the basic principle.

          so now that i have the correct field populating with the parent forms data,
          i want a subform to take this tracking number, and plug it into a query and display all the records relating to that specific number.

          i guess what i am asking is, would this be possible? and would it be the best design for this type of need?

          Comment

          • beacon
            Contributor
            • Aug 2007
            • 579

            #6
            Originally posted by trixxnixon
            oh no, i got it to work with no problem, i still dont quite understand the open argument, but i know how to use the basic principle.
            Open Argument is something that attaches to the command as it performs its action. Not sure that's the best technical explanation for it, but it works for me. Here's a corny analogy to help explain OpenArgs:

            When you run the command, think of it as a pizza being delivered. OpenArgs are the side items that come with the pizza...napkins , parmesan cheese, red pepper, etc. But the pizza delivery place you ordered from doesn't just give you the side items all the time, you have to specify what you want. As long as you specify it, the items will come with your pizza guaranteed (take that Pizza Hut!).

            When the command has run, in your case when it has opened the second form, that's like you accepting the pizza at your front door, as well as the side items. Once you've got the side items, it's up to you how you put them to use. Maybe you put parmesan on pepperoni pizza or red pepper on anchovi (haha) pizza...it's all up to you. This is when you set your text box equal to the me.openargs.

            so now that i have the correct field populating with the parent forms data,
            i want a subform to take this tracking number, and plug it into a query and display all the records relating to that specific number.

            i guess what i am asking is, would this be possible? and would it be the best design for this type of need?
            I'm not sure I understand the second part of your question because I don't have a ton of experience with subforms. Is the tracking number the parameter that you passed through OpenArgs?

            When you open the second form, does the query you're talking about automatically run with all data and now you want to limit the search to just those that match the tracking number?

            Comment

            • FishVal
              Recognized Expert Specialist
              • Jun 2007
              • 2656

              #7
              Here you may find some additional indormation on this topic.

              Regards,
              Fish

              Comment

              • trixxnixon
                New Member
                • Sep 2008
                • 98

                #8
                Originally posted by beacon
                Open Argument is something that attaches to the command as it performs its action. Not sure that's the best technical explanation for it, but it works for me. Here's a corny analogy to help explain OpenArgs:

                When you run the command, think of it as a pizza being delivered. OpenArgs are the side items that come with the pizza...napkins , parmesan cheese, red pepper, etc. But the pizza delivery place you ordered from doesn't just give you the side items all the time, you have to specify what you want. As long as you specify it, the items will come with your pizza guaranteed (take that Pizza Hut!).

                When the command has run, in your case when it has opened the second form, that's like you accepting the pizza at your front door, as well as the side items. Once you've got the side items, it's up to you how you put them to use. Maybe you put parmesan on pepperoni pizza or red pepper on anchovi (haha) pizza...it's all up to you. This is when you set your text box equal to the me.openargs.



                I'm not sure I understand the second part of your question because I don't have a ton of experience with subforms. Is the tracking number the parameter that you passed through OpenArgs?

                When you open the second form, does the query you're talking about automatically run with all data and now you want to limit the search to just those that match the tracking number?

                right after i posted this i was able to get it working,

                thanks for your help by the way, i hope one day i can return the favor.

                Comment

                • trixxnixon
                  New Member
                  • Sep 2008
                  • 98

                  #9
                  Originally posted by FishVal
                  Here you may find some additional indormation on this topic.

                  Regards,
                  Fish
                  you really know your stuff. how long have you been doing this?

                  Comment

                  Working...