[AccessD] Go to today

A.D.TEJPAL adtp at hotmail.com
Thu May 31 09:33:33 CDT 2007


Arthur,

    Subroutine  P_GoToNearestToToday(), as given below, can be placed in form's module and called as required.

    It will ensure that you land up at today's date or the next higher one if there is no entry for today's date.

    If there is no entry for date >= today, you will land up at the date earlier than but closest to today, which, in such a situation, will simply be the last record.

    Note:
    (a) RDate is the presumed name of date field.
    (b) It is presumed that dates are sorted in ascending order.

Best wishes,
A.D.Tejpal
---------------

====================================
Private Sub P_GoToNearestToToday()
    On Error Resume Next
    Dim rst As DAO.Recordset
    
    Set rst = Me.RecordsetClone
    
    rst.FindFirst "RDate >= #" & _
            Format(Date, "mm/dd/yyyy") & "#"
    
    If rst.NoMatch Then
        rst.MoveLast
    End If
    
    Me.Bookmark = rst.Bookmark
    
    rst.Close
    Set rst = Nothing
End Sub
====================================

  ----- Original Message ----- 
  From: Arthur Fuller 
  To: Access Developers discussion and problem solving 
  Sent: Wednesday, May 30, 2007 20:48
  Subject: [AccessD] Go to today


  It's been a while since I've done an Access FE and I'm rusty. Here's the situation. There's a table whose data includes stuff from a few years back and up to mid-next-year (events, already-occurred and scheduled to occur). 

  I want to open the form on the closest date >= today. There is also a filter, by Employee. The form begins with all Employees but should you elect to set the filter, then it's scoped by selected Emp. But I still want the date thing to work.

  In the combo-box for Emp filter there's a union with an "All" case at the top, which choice simply wipes out the existing filter on Emps (if any).

  I do NOT want to filter out the events prior to today. I just want to open the form at today or the nearest date beyond today, and I also want to respect the Emp filter.

  Advice?

  TIA,
  Rusty old Arthur, who has been spending way too much time in SQL Server to remember all these fancy shenanigans. :)


More information about the AccessD mailing list