I have a form which allows users to enter a month/year, or enter a quarter and year, for each entry. The report which displays the data uses a query which combines those fields into one field [XXX] which holds either mmm-yyyy, or if that is null, then yyyyQq.
When the query runs it drops the rows in the correct descending sort order for the field [XXX]. But the report detail section, where the [XXX] field and the others displayed are shown forces a choice of sorting ascending or descending, but it’s alpha or numeric, not in date order. Thus Mar-2002 is followed by Jan-2002, followed by Feb-2002 etc.
Is there a way to make the detail section sort in date order? Or to rewrite the query /add a numeric field it can use?
Thanks in advance. You all are so good at answering questions.
Judy
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
sort order problem (’97)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » sort order problem (’97)
- This topic has 38 replies, 7 voices, and was last updated 22 years, 2 months ago.
AuthorTopicWSdevore1
AskWoody LoungerApril 6, 2002 at 8:45 pm #369254Viewing 1 reply threadAuthorReplies-
WSpatt
AskWoody LoungerApril 6, 2002 at 9:23 pm #580973If you have a date as part of the underlying source of the report, then yes you can sort on this date.
Are you asking how to sort in a report, if so, click on View in report design view and choose Sorting and Tab order.
Next select from the left column the field you wish to sort on and from the right hand column choose Ascending or Descending.I hope I have understood your question.
Cheers,
Pat -
WBell
AskWoody_MVPApril 6, 2002 at 11:42 pm #580982Pat is on the right track, but from your description of the field you want to sort on, it isn’t a date. In order to make it a date, you want to use the DateSerial function. You specify Year, Month, and Day of Month as inputs to the function – if you don’t know the day of the month, simply make it 1. Then you can format it on the report as MMM-yyyy and it will display correctly and sort correctly.
-
WSdevore1
AskWoody LoungerApril 6, 2002 at 11:58 pm #580985Hi Pat and Wendell,
I do know how to make a field sort in a report, but it only allows an alpha or numeric sort, not a date sort for what I created. And making a combined field be a date when I have both yyyyq and mmm-yyyy – well, it wants to look at the results as a text field not a date field. I assume that’s because the data is mixed. Some values are 2000Q1 where =”yyyy”& “Q”& “q” and others are Jan-2000 where =”mmm-yyyy”.
I’ve considered forcing all Q1 values to equal Mar etc, but it then is hard to distinguish between actual quarter values and month values. The data being entered can be done monthly, quarterly, semi-annually, once only, etc. and I wanted to make it as flexible as possible.
Judy -
WSBat17
AskWoody Lounger -
WSdevore1
AskWoody LoungerApril 7, 2002 at 7:02 pm #581034That’s fine, but since folks may enter information in any order, choosing to use entry date, or ID#, won’t work. It would have to be something that actually did sort against the real date value and assign a different, sortable value. And I havenm’t figured out the best approach for that.
If I wanted to set up a field, or query value, of Q1=March, Q2=June, etc., what would be the best way to write that so the value carried forward to the combined field?
-
-
WBell
AskWoody_MVPApril 7, 2002 at 2:35 pm #581007This does get kind of sticky – the trick with date sorts is that they are really numeric. Date fields are actually stored as a certain number of days from long ago (I forget what the actual zero date is, but something like 1/1/1900) as the integer portion, and the hours, minutes and seconds as the decimal portion. So when you sort a date field you are actually doing numeric sort.
So the trick is to create a pseudo date from the information the user enters so you can sort on it. Bat17’s suggestion of a hidden field is a good one, but you can also display the pseudo date so it looks like the entry made by the user if you use the formatting capabilities. If you want to display the data just as the user entered it, then the hidden field pseudo date is probably the best approach. Hope this helps.
-
WSdevore1
AskWoody Lounger -
WBell
AskWoody_MVPApril 7, 2002 at 11:19 pm #581056The only way I know of to make it numeric AND make it sort in date order is to force in into a date with the DateSerial function. In that case it definitely will be. To do that you will have to parse the input data to figure out which kind it is, and then plug in a psuedo date as I suggested. In other words, if it turns out to be MM/YYYY then you would use
SortDate: DateSerial(YYYY,MM,1)
but it it is quarters then you would need to do a bunch of IFs, or a Select statement – it would look something like this
SELECT CASE Quarter
CASE Q1
SortDate = DateSerial(YYYY,4,0)
CASE Q2
SortDate = DateSerial(YYYY,7,0)
CASE Q3
SortDate = DateSerial(YYYY,10,0)
CASE Q4
SortDate = DateSerial(YYYY+1,1,0)
END SelectOf course you can’t use Select statements in queries, but it occurs to me that if the user isn’t putting in true dates then you will need to do a fair bit of validation as they enter the date. In that case you could use the code to calculate the date and actually save it in the record. Otherwise you would have to resort to doing record sets with DAO or ADO – a fair bit more comples than just using a form bound to a query. Actually, it seems to me you will need code anyhow – I assume the date is being put into a single field and is stored either as MM/YYYYor Qx/YYYY, so you will need to do some validation to be sure that they put in either a valid month or valid quarter and a valid year – presumably either the current year or last year. So you will already have a fair bit of VBA going on already – might as well do it then and there.
I should add that I used a trick in the SELECT statements – when you do a date serial with the day set to zero (0) it returns the last day of the month. That way the dates would sort with Jan, Feb, Mar, Q1, Apr, May, Jun, Q2 and so on. Hope this isn’t too muddled an explanation.
-
WScharlotte
AskWoody Lounger -
WSdevore1
AskWoody LoungerApril 8, 2002 at 12:53 am #581062Actually, there are 3 fields -field 1 for entering month/year; field 2 for quarter and field 3 for year. I’m having to make a query field to combine the quarter and year, another to put the quarter and year plus the month-year in one filed, and now I’ll have to work against that.
I’m sure there is an easier way to set it up, but….. I didn’t hink one could have two types of dates in one input field.
Thanks, I’ll let you know what I figure out. I’ll play with this when I get back to work tomorrow. -
WSBat17
AskWoody LoungerApril 8, 2002 at 5:43 am #581074Reading your post again, I see that the query returns the results in the right order for you. If you are not doing further sorting/grouping within the report, then make sure that the OrderByOn property is set to yes in the property sheet and it should sort in the same order asthe query.
HTH
Peter
-
WSdevore1
AskWoody LoungerApril 8, 2002 at 12:49 pm #581113I just tried this, but no luck. I even made a group header and put the ‘when’ field in it, but it still sorts as text. The query is taking two date fields and putting them in one If/Then field. Is there a way to make the new If/Then field think it is dates rather than text? How can that be done when there are two types of dates?
I suspect Wendell was correct- I’m going to have to force quarters into months, somehow. I’ll keep trying.
Thanks for the suggestion – it sounded great.
-
WSBat17
AskWoody LoungerApril 8, 2002 at 1:28 pm #581117You could use a custom function in the query to add a “serial” number to your data and sort by that.
Function funAddSer(var As Variant)
Static lngCounter As Long
lngCounter = lngCounter + 1
funAddSer = lngCounter
End Functionand call it with lngCounter:funAddSer([some field name here])
It seems to need a field name passed to it for it to work!
HTH
Peter
-
WSdevore1
AskWoody LoungerApril 11, 2002 at 3:27 pm #581839My apologies for the delay, but when I went to the query to add this function, I couldn’t figure out how to do that. I don’t see how to build code in the query other than SQLview.
I have
ORDER BY [Ongoing Data].MONTHYEAR DESC , IIf([MONTHYEAR] Is Not Null,Format([MONTHYEAR],”mmm yyyy”),[YEAR] & “Q” & [QUARTER]) DESC;Can you help me further so I can add your function?
Thanks – Judy -
WSpatt
AskWoody Lounger -
WSdevore1
AskWoody LoungerApril 13, 2002 at 3:49 am #582186That would work just fine, except I haven’t figured out how to make a single format date field from what I have. Wendell sent a set of select statements but I’m not sure how those get built into the query itself. I could possibly write an If..then code for a Expression1 type field, or try a multiple IIf() or IIf () or type statement. I just don’t know the best way to write what is needed.
Judy -
WSpatt
AskWoody LoungerApril 13, 2002 at 5:54 am #582195If you can guarantee that the [QUARTER] value is indeed 1,2,3 or 4 then try the following in a query:
iif(isnull([MONTHYEAR]), DateSerial([YEAR], [QUARTER]*3+1,0), CDate([MONTHYEAR])) as SpecialDate
This could then be used in the ORDER BY clause.
I have used clues by both Charlotte(CDate) and Wendell (0 day in DateSerial returning the last day of the previous month).I hope this helps,
Pat -
WSdevore1
AskWoody LoungerApril 16, 2002 at 2:05 am #582616I’m stymied! I’ve tried various different things and still can’t get it to work. I’ll attach a pared down version here in the hopes that someone else will be able to see whatever it is that I am missing. It contains three different ID#s – 123, 311 and 378. All of them have entries in both styles – month year and quarter year. No matter what I try it sorts Mar Jan Feb. And now that I changed it to include the Special Date statement, it doesn’t even give back all the rows it should.
In advance, I thank you all…….Judy -
WSpatt
AskWoody LoungerApril 16, 2002 at 7:21 pm #582794Hi Judy,
Try the following at the front of the query:
PARAMETERS [Start Date] DateTime, [End Date] DateTime;What this effectively does is to signal WHEN to be a date field. I can cerrtainly get a lot of records (20 for 1/1/00 thru 16/4/02 for 123,311,378) returned.
I have posted your changed sample db back to you.Hope this solves the problem!!
Pat -
WSdevore1
AskWoody Lounger -
WSpatt
AskWoody Lounger -
WSdevore1
AskWoody Lounger -
WSpatt
AskWoody Lounger -
WSdevore1
AskWoody Lounger -
WSpatt
AskWoody Lounger -
WScharlotte
AskWoody LoungerApril 19, 2002 at 3:28 am #583315You can hide them by setting their dbHiddenObject property to true, but doing that in Access 97 is an extremely bad idea since they will be deleted when the database is compacted. I’ve never tried it with Access 2000. The other way is to use the UI property dialog of the table and check the Attributes: Hidden checkbox.
-
WSpatt
AskWoody LoungerApril 19, 2002 at 6:48 am #583323Thanks Charlotte.
I don’t know how to set the dbHiddenObject property to true. How do you do that?The other way (set the Attributes: Hidden checkbox after right clicking on the table and into properties) is the way I would go as this nicely hides the table from being changed by prying eyes.
Pat -
WSdevore1
AskWoody LoungerApril 19, 2002 at 4:00 am #583317You can hide tables, forms, queries – whatever you don’t want other users to see. What they can’t see they can’t change.
Highlight the item you want to hide , for instance under the table tab highlight one of the tables. [You have to do this one by one] Right mouse on the highlighted item, scroll down to Properties.That will bring up another screen and in the lower left corner is a box you can click to hide the item. Now when you open the db, you will still be able to see it. But when someone else opens it as a shared application, that item will not be visible.
Let me know if that works for you. -
WSpatt
AskWoody Lounger -
WSBat17
AskWoody Lounger -
WSpatt
AskWoody Lounger -
WSdevore1
AskWoody Lounger -
WSpatt
AskWoody Lounger -
WSdevore1
AskWoody Lounger -
WBell
AskWoody_MVPApril 13, 2002 at 1:46 pm #582211Unfortunately, you can’t use a SELECT statement in a query, as it is VBA. I was assuming that you would run a small VBA routine on the BeforeUpdate event of the data entry form that would probably update a hidden control on your form containing the field with the real date format bound presumably to a new date field in your table. If you want to try it at the query level, look at the SWITCH funtion – I believe it’s available for use in queries. As long as you aren’t dealing with lots of possibilities, it might do what you need in converting the Q entries into date fields. Also, Charlotte’s suggestion of using CDate on the field as you enter it would obviate the need for complicated statements in the query. In fact that might let you simplify things so you don’t need as many entry fields. I presume that if someone goes back and looks at the form after data has been entered, you would want them to see the data exactly as they entered it. If that isn’t a requirement you may be able to get by with one date field.
-
WSdevore1
AskWoody LoungerApril 13, 2002 at 4:09 pm #582233 -
WSnuglorious
AskWoody LoungerApril 2, 2003 at 6:52 am #665697i having problem trying to sort in order of alphabetical in unbound textbox. What I’m trying to show is after the user have selected an items from combobox then it shall display some data inthe detail form. But user have some difficult to see whos comes first. So in order to have a data in order the user want to specific by account name in order. How do make it happen?pls help..
-
WSHansV
AskWoody LoungerApril 2, 2003 at 7:20 am #665702You wrote “sort in order of alphabetical in unbound textbox” – do you want to sort text within a text box? Seems strange…
Or did you mean that the data in the combo box (not text box) should be sorted? I assume that the Row Source of the combo box is a table now. In that case, create a query based on the table that selects the account names in alphabetical order, and use this query as Row Source of the combo box. If the Row Source is a query already, edit it and make it sort on account name.
-
-
-
-
Viewing 1 reply thread -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
AI is good sometimes
by
Susan Bradley
1 minute ago -
Mozilla quietly tests Perplexity AI as a New Firefox Search Option
by
Alex5723
1 hour, 3 minutes ago -
LibreOffice 25.8. No Windows 7, 8/8.1, x86
by
Alex5723
4 hours, 6 minutes ago -
Perplexity Pro free for 12 mos for Samsung Galaxy phones
by
Patricia Grace
20 hours, 2 minutes ago -
June KB5060842 update broke DHCP server service
by
Alex5723
18 hours, 34 minutes ago -
AMD Ryzen™ Chipset Driver Release Notes 7.06.02.123
by
Alex5723
22 hours, 36 minutes ago -
Excessive security alerts
by
WSSebastian42
1 hour ago -
* CrystalDiskMark may shorten SSD/USB Memory life
by
Alex5723
1 day, 8 hours ago -
Ben’s excellent adventure with Linux
by
Ben Myers
1 hour, 23 minutes ago -
Seconds are back in Windows 10!
by
Susan Bradley
19 hours, 13 minutes ago -
WebBrowserPassView — Take inventory of your stored passwords
by
Deanna McElveen
1 hour, 46 minutes ago -
OS news from WWDC 2025
by
Will Fastie
5 hours, 21 minutes ago -
Need help with graphics…
by
WSBatBytes
3 hours, 23 minutes ago -
AMD : Out of Bounds (OOB) read vulnerability in TPM 2.0 CVE-2025-2884
by
Alex5723
1 day, 23 hours ago -
Totally remove or disable BitLocker
by
CWBillow
22 hours, 40 minutes ago -
Windows 10 gets 6 years of ESU?
by
n0ads
1 day, 1 hour ago -
Apple, Google stores still offer China-based VPNs, report says
by
Nibbled To Death By Ducks
2 days, 10 hours ago -
Search Forums only bring up my posts?
by
Deo
4 hours, 45 minutes ago -
Windows Spotlight broken on Enterprise and Pro for Workstations?
by
steeviebops
2 days, 22 hours ago -
Denmark wants to dump Microsoft for Linux + LibreOffice
by
Alex5723
2 days, 14 hours ago -
How to get Microsoft Defender to honor Group Policy Setting
by
Ralph
2 days, 22 hours ago -
Apple : Paragon’s iOS Mercenary Spyware Finds Journalists Target
by
Alex5723
3 days, 8 hours ago -
Music : The Rose Room – It’s Been A Long, Long Time album
by
Alex5723
3 days, 9 hours ago -
Disengage Bitlocker
by
CWBillow
2 days, 23 hours ago -
Mac Mini M2 Service Program for No Power Issue
by
Alex5723
3 days, 11 hours ago -
New Win 11 Pro Geekom Setup questions
by
Deo
4 hours, 49 minutes ago -
Windows 11 Insider Preview build 26200.5651 released to DEV
by
joep517
3 days, 19 hours ago -
Windows 11 Insider Preview build 26120.4441 (24H2) released to BETA
by
joep517
3 days, 19 hours ago -
iOS 26,, MacOS 26 : Create your own AI chatbot
by
Alex5723
3 days, 23 hours ago -
New PC transfer program recommendations?
by
DaveBoston
2 days, 3 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.