Having a problem with query criteria coming from a subform

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ajhayes
    New Member
    • Feb 2009
    • 9

    Having a problem with query criteria coming from a subform

    Hello everyone,

    This is my first time posting here and I'm hoping someone can help me out. I'm a relative newbie to Access and am pretty much learning as I go along, so please bear with me.

    Here is what I am trying to do. I'm building a simple database that will allow our engineering staff to enter in the items from the inventory warehouse that will be required for a project. Each inventory item has a unique part number, which is entered by the user.

    I have a query set up that pulls all of the required information together, and then there is a report based on this query.

    What I am ultimately trying to do is have a command button at the end of the order form that allows the user to print the order based on the current order number in the form.

    I have set up the query criteria using:
    [forms]![frm_Ordered_Ite ms]![order_number]

    If I have the frm_Ordered_Ite ms open by itself, and put a command button at the bottom to open the report based on the query using this criteria, it works perfectly.

    The problem is that I've set up the form as a sub-form, and once it's nested into the other form, a popup button comes up and calls for the query parameter to be entered manually. How can I change this so that it will perform the query and bring up the report automatically?

    I hope I've given enough information to explain the situtation clearly.
  • DonRayner
    Recognized Expert Contributor
    • Sep 2008
    • 489

    #2
    If you are trying to refer to a subform, you must first refer to the control on the main form that contains it. Then you can refer to the controls on the subform.

    Code:
    Forms!MainForm!frm_Ordered_Items.Form!order_number
    Just replace MainForm with whatever the name is of your main form.

    Welcome to Bytes

    Don

    Comment

    • ajhayes
      New Member
      • Feb 2009
      • 9

      #3
      Okay, I just cheered out loud in the middle of my super quiet office... everyone is wondering what the heck I'm up to now. :-)

      That was exactly the fix. I've googled it a billion times and couldn't find the right syntax.

      Thank you SO much!!

      Comment

      • DonRayner
        Recognized Expert Contributor
        • Sep 2008
        • 489

        #4
        Glad I could help, good luck with your project.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32653

          #5
          Check out Referring to Items on a Sub-Form for a bit more background.

          Welcome to Bytes!

          Comment

          • ajhayes
            New Member
            • Feb 2009
            • 9

            #6
            Thanks for that link, that will be a big help in the future.

            Printing that out for my stash of references.

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32653

              #7
              You're welcome AJ.

              Do you realise we also have a whole forum (Access Insights) just for such articles. To a large extent they are responses to Frequently Asked Questions. Issues that come up over and over again. There's other stuff there too, but it's where we put the answers we need to link to most.

              Comment

              • rufinojr54
                New Member
                • Apr 2022
                • 2

                #8
                Hi!

                I think, I have the same problem but still wasn't able to fix it. Mine is 2 combo boxes, the 2nd combo box is based on a query, getting values related to the 1st combo box. It is working perfectly when not as a subform. But, when I make it as a subform, a parameter value is asked. How do I fix it? And, in ExpenseDetail table, I put, ExpenseID, which is a primary key in ExpenseT, also a table. Will I only be able to generate ExpenseIDs if I can fix my problem above? Please help!


                Thanks,

                Comment

                • rufinojr54
                  New Member
                  • Apr 2022
                  • 2

                  #9
                  This worked for me now. Just changed the name of the subform then followed your syntax. 👏👏👏👍🙏

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32653

                    #10
                    Please understand that we don't encourage extra questions to be posted into existing threads. That would get very messy very quickly.

                    Nevertheless, in this case, as you have already posted that you've got the answer from here, we'll treat it just like a simple Thank you. post which are allowed of course.

                    Comment

                    Working...