PC Review


Reply
Thread Tools Rate Thread

Form: OrderBy minimum of fields

 
 
New Member
Join Date: Nov 2010
Posts: 2
 
      9th Nov 2010
Hello,

I have a table (Access 2003) which contains among others three date fields D1, D2, D3. I have a form
showing one record at a time; for the sequence of the records, I set the OrderBy property
of the form with VBA. I want the records to be sorted according to the oldest of the three dates.

What works is:

Me.OrderBy = "D1,D2,D3"
Me.OrderByOn = True

This, however, sorts first by D1, then by D2, then by D3. What I want, is sorting
by the minimum of the three dates, so that the records where one of them is old appear first:

Me.OrderBy = "Min(D1,D2,D3)"

But this doesn't work. Firstly there is no Min function that compares fields within
one record, but every attempt to a workaround fails since apparently no expressions or
functions at all can be used in the OrderBy property of the form. If I put e.g.

Me.OrderBy = "Fix(D2)"

then on opening the form a pop-up dialog appears: "Enter parameter value: 'Fix(D2)' ", so
appearently the expression is not recognized.

I also do some filtering. Here I use:

Me.Filter = "((D2<=Now()) AND (F2=0)) OR ((D3<=Now()) AND (F3=0))"
Me.FilterOn = True

This works, so some complex expression can be used at least for filtering; but apparently
not for ordering.

Any idea how I can get the ordering working?

Thanks

Henrich
 
Reply With Quote
 
 
 
 
New Member
Join Date: Nov 2010
Posts: 2
 
      13th Nov 2010
I have now found a solution. Expressions are (apparently) not allowed in the OrderBy property of Access forms, but in the OrderBy clause of queries. So I have changed the form's RecordSource from the table to:

Me.RecordSource = "SELECT * FROM Tabelle ORDER BY Hmin(D1,D2,D3);"
Me.Requery

where I use a user-defined function Hmin (placed in a new module of the database, not of the form) which calculates the minimum of several input arguments.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OrderBy two fields Leslie Isaacs Microsoft Access Forms 1 17th Apr 2007 02:01 PM
orderby works with yes/no fields? GIL-PT via AccessMonster.com Microsoft Access Forms 3 17th Feb 2007 01:42 AM
How to lookup the minimum, 2nd minimum and 3rd minimum......... Mark McDonough Microsoft Excel Worksheet Functions 8 15th Jul 2006 09:39 PM
OrderBy with multiple fields Tim Otero Microsoft Access Macros 1 28th Jun 2006 08:18 PM
OrderBy (form) and ORDERBY (sql) Gurtz Microsoft Access Form Coding 4 17th Aug 2003 06:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:23 PM.