ms-access-2010

Access 2010 Query with Parameter and Sort


I have a problem that I've been going round and round with in Access 2010. Imagine a table with these columns:

Name Date Time

Now, I have a query that asks the user to input a begin date and an end date and returns all records that are between those two dates. This works fine. However, as soon as I add a sort to the Date column things go awry. Once you put a sort on a column with a parameter the user gets asked to enter the parameter twice. From what I've been able to find out this is normal (although annoying) behavior in Access.

If I add the Date column in a second time and show the column with the sort and don't show the column with the parameter it works fine. The query would look something like:

Name Date (shown & sorted) Date (not shown & parameters) Time

Now when I run the query it all works well and comes out the way I want it to. This would obviously be a great solution then. However, there's another problem. When I save the query, leave, and reopen the query the two columns are merged back into each other. Thus, the change is lost and the user again sees two inputs.

My question is this: what can I do differently to achieve the desired results?

Some possible things I've thought about but don't know the answer to are:

Is there a way to make it so the columns don't merge? Do I have to use a form with the input boxes and take the data from that (I'd prefer not to do that as it will require a lot of additional work to handle the various things I am doing in the database). Is there some obvious thing I'm missing?

Thanks for any suggestions.

FYI: Here is the SQL from the query

SELECT Intentions.Intention, Intentions.MassDate, Intentions.[Time Requested], Intentions.[Place Requested], Intentions.[Offered By], Intentions.Completed
FROM Intentions
WHERE (((Intentions.MassDate) Between [Enter start date] And [Enter end date]))
ORDER BY Intentions.MassDate, Intentions.[Time Requested];


Solution

  • It is true that sometimes the Query Designer in Access will "reorganize" a query when you save it. However, I don't recall an instance where such a reorganization actually broke anything.

    For what it's worth, the following query seems to do what you desire. After saving and re-opening it looks and behaves just the same:

    DateQuery.png

    For reference, the SQL behind it is

    PARAMETERS startDate DateTime, endDate DateTime;
    SELECT NameDateTime.Name, NameDateTime.Date, NameDateTime.Time
    FROM NameDateTime
    WHERE (((NameDateTime.Date) Between [startDate] And [endDate]))
    ORDER BY NameDateTime.Date DESC , NameDateTime.Time DESC;