Access - Sorting on a combined CLng field

I combined two fiellds - with Clng as suggested. This does return a numeric field.

I have combined YYYYMM in this order, hoping that when I sort on this - the oldest year will come first.

Unfortunately, even though the year is first - when I sort ascending - it sorts by MM first, so that 20151 comes before 201412.

Please advise.

Thank you.
exp vgAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chaauCommented:
When converting the date to long integer use this formula:
Year(dateField) * 100 + Month(dateField). In this case the value for Jan-2015 will be 201501 (not 20151) and it will come before the Dec-2015 (which will be 201512)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
exp vgAuthor Commented:
Thank you so much - this helps immensely.
Dale FyeOwner, Developing Solutions LLCCommented:
This is the reason in all of my previous responses to your date questions that I recommended the "yyyy/mm" format.  this will display January as 201501, Feb as 201502, which will sort as less than 201512.

If you are going to continue to work with dates converted to strings, I strongly recommend that you do your conversion using two character months and dates:

Format([DateField], "yyyy/mm/dd")
Format([DateField], "yyyy/mm")
exp vgAuthor Commented:
Got it...thanks. The format statement leaves it as text, and I thought that any text field would not sort properly. But not the case with yyyymm.

Thank you everyone.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.