Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / March 2006

Tip: Looking for answers? Try searching our database.

Select query using a date field

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
PRH - 15 Mar 2006 08:06 GMT
I have a table in which each record has a date associated with it. I need to
extract the record that has a date closest to a date entered on a form.
Specifically, it needs to be the record that is the highest in the table but
lower than or equal to the date on the form e.g. if the table contains
records with 20/01/2006, 20/2/2006 and 20/03/2006 and 01/03/2006 is entered
to the form, then I want to extract the record dated 20/02/2006.

How can this be done?
John Spencer - 15 Mar 2006 13:46 GMT
You need to use the TOP predicate in a query.  A generic example follows

SELECT TOP 1 SomeDate
FROM SomeTable
WHERE SomeDate <= Forms![YourFormName]![YourDateControl]
ORDER BY SomeDate Desc, [PrimaryKeyField in SomeTable]

TOP can return more than one record if there is a tie in the sort order.  If
you want to avoid ties then your sort order should have fields in it that
will force a unique sort order.  In one table queries that would be the
field(s) making up the primary key.

If you are trying to do this in the grid, you can set TOP using the query's
property sheet.

>I have a table in which each record has a date associated with it. I need
>to
[quoted text clipped - 7 lines]
>
> How can this be done?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.