Share via

Form based parameter query

Anonymous
2020-11-12T11:20:54+00:00

I have created an unbound form (frmInvParameters) with controls txtDepart_FROM, txtDepart_TO (with Data Type of Short Date) and txtWhich_Venue and a button to run the query qryInvs.

In qryInvs I have put Between [Forms]![frmInvParameters]![txtDepart_FROM] And [Forms]![frmInvParameters]![txtDepart_TO] in criteria of DepartDate field and Like "*" & [Forms]![frmInvParameters]![txtWhich_Venue] & "*" in the Venue field's criteria. Show check boxes have a tick in each.

But on entering control values on the form and running the query I am being asked to "Enter Parameter Value" for txtDepart_From, txtDepart_TO and txtWhich_Venue.  If I simply click OK on these dialog boxes without entering anything the query runs and correct results are produced.  If I enter values in these boxes same as or different to those on the frmInvParameters they are ignored and query produces results per the settings in the form.

 Is there some way to stop those dialogs appearing as they are not necessary?

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

9 answers

Sort by: Most helpful
  1. Anonymous
    2020-11-13T09:18:33+00:00

    I don't understand what you mean by fully qualified.  This is what I have in the Criteria and seems to be in line with what you are suggesting:

    Between [Forms]![frmInvParameters]![txtDepart_FROM] And [Forms]![frmInvParameters]![txtDepart_TO]

    Is this not how it should be?

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2020-11-12T17:54:34+00:00

    Unless you really wish to do substring matching on the VenueCode column, rather than simply making the venue parameter optional, I would also recommend that you change:

    ((Venues.VenueCode) Like "*" & [Forms]![frmInvParameters]![txtWhich_Venue] & "*")

    to:

    (Venues.VenueCode =  [Forms]![frmInvParameters]![txtWhich_Venue]

    OR [Forms]![frmInvParameters]![txtWhich_Venue] IS NULL)

    The LIKE operator does not allow for Nulls at the Venue column position, and any such rows would not be returned.  Also, the above syntax allows the optimizer to make use of the index, which will benefit performance.

    If you do the above you should also omit the [Forms]![frmInvParameters]![txtWhich_Venue] parameter from the PARAMETERS clause.  A parameter declared as TEXT can never evaluate to NULL.  Using a combo box rather than the txtWhich_Venue control in the form would make for greater accuracy, as the user would then be constrained to entering or selecting a value which exists in the database.

    Was this answer helpful?

    0 comments No comments
  3. Duane Hookom 26,820 Reputation points Volunteer Moderator
    2020-11-12T17:27:53+00:00

    I would chang e the PARAMETERS to be fully qualified with [Forms]![frmInvParameters]!

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2020-11-12T14:39:32+00:00

    This is the SQL, I have removed some of the fields which are not relevant:

    PARAMETERS [txtDepart_FROM:] DateTime, [txtDepart_TO:] DateTime, [txtWhich_Venue] Text ( 255 );

    SELECT DISTINCTROW Bookings.VenueID, Bookings.ArrivalDate, CVDate(DateAdd("d",Nz([Nights],0),Nz([ArrivalDate],0))) AS DepartDate, Venues.VenueCode, Bookings.ReservataionID, Bookings.VenueRef, Bookings.Nights, Bookings.CustomerID, Bookings.Guest, Venues.VenueName, [TAXrate].[stdTAXrate],0) AS TAXr, Bookings.DateCancelled

    FROM TAXrate, Venues INNER JOIN Bookings ON Venues.VenueID = Bookings.VenueID

    WHERE (((CVDate(DateAdd("d",Nz([Nights],0),Nz([ArrivalDate],0)))) Between [Forms]![frmInvParameters]![txtDepart_FROM] And [Forms]![frmInvParameters]![txtDepart_TO]) AND ((Venues.VenueCode) Like "*" & [Forms]![frmInvParameters]![txtWhich_Venue] & "*") AND ((Bookings.DateCancelled) Is Null)

    ORDER BY Bookings.VenueID, Bookings.ArrivalDate, Bookings.ReservationID;

    Was this answer helpful?

    0 comments No comments
  5. George Hepworth 22,855 Reputation points Volunteer Moderator
    2020-11-12T13:40:04+00:00

    Please show the entire SQL from that query. Sometimes that helps spotting unanticipated problems that might otherwise be overlooked.

    Was this answer helpful?

    0 comments No comments