vbadatetimems-access-2010datetime-formatdatetimeformatinfo

Date/Time datatype ms access 2010 month names in proper yearly order


I have been reading all of the advice available about how to get month names in the proper yearly order. Each piece of information seems to focus on something slightly different and I'm still a bit confused - should I be applying the MonthName vba function in my form? Or does something else work...? Another thread even suggests to create another table that provides integer values for each month name - to me however, this seems like an inelegant solution (no offense intended).

I'm using MS Access 2010 and I want my month names in my form to be displayed in proper yearly order (January through to December). What would the code be and where would be the best place to put it?

The record source for the form is the SQL query which is:

SELECT Format([DateOfEnquiry],"mmmm") AS [Month], Count(T_Enquiry.DateOfEnquiry)
AS TotalMonthlyEnquiries
FROM T_Enquiry
GROUP BY Format([DateOfEnquiry],"mmmm"), [Enter full name of month]
HAVING ((([Enter full name of month]) Is Null)) OR (((Format([DateOfEnquiry],"mmmm"))=
Enter full name of month]) AND (([Enter full name of month]) Is Not Null));

But the form displays the month names in alphabetical order not in their proper yearly order. The data type for the DateOfEnquiry field in the T_Enquiry table is set to Date/Time. I have read other Stack Overflow threads that suggest VBA code attached to the form "overrides" the query statement. So, my question becomes - where is the best place for the appropriate vba code to be inserted and what would the correct code be to sort/order the month names from January to December?


Solution

  • I have found one solution that I tested and it seems to work well in my database. I created a new field within the query - 'Format([DateOfEnquiry], "mm")' - and used this field for sorting.