• Run a parameter query from an Access form (VBA Access2003/WindowsXP)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Run a parameter query from an Access form (VBA Access2003/WindowsXP)

    Author
    Topic
    #423225

    How do I pass a parameter from a form that requests needed data (like a name) to a query that needs that data? Writing a parameter query is straight forward, but its method of requesting its parameter is by the pre-defined use of its little parameter request window. Running a query from a form is also straight forward, but I can see no way, after the form has requested and received the parameter data, of passing it to the query. (The DoCmd OpenQuery Method, as an example, has no capability to pass along the parameter information.)

    Thank you for your time and help,

    John Littell

    Viewing 1 reply thread
    Author
    Replies
    • #967752

      To have a query refer to the value referred to on the form, in the criteria use a statement like this:

      IIf(IsNull([forms]![YOURFORM]![INPUT SOURCE CONTROL HERE]),[FILTERED FIELD NAME HERE],[forms]![YOURFORM]![INPUT SOURCE CONTROL HERE])

    • #967774

      Jeremy’s reply lets the query return all records if the parameter is left blank. If you simply want to replace the parameter prompt with a reference to the form, change the criteria from something like

      [Enter name]

      to

      [Forms]![frmMyForm]![txtName]

      where frmMYForm is the name of the form, and txtName is the name of the text box on the form in which the user enters the name information.

      • #967797

        Jeremy and Hans,
        Thank you for your replys. Once I realized that the form would still be open and accessable, it all fell into place. Works fine.

        John

        • #967846

          John,
          If you run into the case where you must (or want to) close the form, you could do one of two things…create a hidden form that will store the value of the box, and refer to that, or store the value as a global variable.

    Viewing 1 reply thread
    Reply To: Run a parameter query from an Access form (VBA Access2003/WindowsXP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: