Search code examples
vbams-accessoffice365ms-office

Pass query arguments to report


I have a report in MS Access that takes information from a query.

In the query there is time selection so that it displays information between a time interval set by the user.

The criteria I used to create this is:

Between [Enter start date:] And [Enter end date:]

I want the start date and end date to be displayed in my report as soon as the user inputs it.

I tried creating 2 text boxes and using the same code but what I end up with is the same input box twice when in reality I just want the input to be done only once.

Can anyone help me?


Solution

    • On your form, create two unbound textboxes:
      Name the first textbox StartDate and the second textbox EndDate.

    • Set the Format property for both textboxes to General Date to ensure that the user may only enter datetime data and is presented with a date picker.

    • In the selection criteria for your query, replace the following:

      [Enter start date:] with Forms![Your Form Name]![StartDate]

      [Enter end date:]     with Forms![Your Form Name]![EndDate]

      Change Your Form Name to the name of your form.

    • If you wish to also display the entered dates on your report, create one or two textboxes on the report whose Control Source is set to:

      =Forms![Your Form Name]![StartDate]
      

      Similarly for the End Date.