Results 1 to 2 of 2

Thread: Compare stored date with today's date

  1. #1
    Join Date
    Apr 2005
    Posts
    7

    Compare stored date with today's date

    OK, I have a form that has a button on. When that button is clicked it launches a report. This report should only contain records where the date stored in CourseMotivateDate is before today's date.

    How can I do the date comparison? I tried simply using "[CourseMotivateDate] < " & Date but that didn't work.

    I have pasted my Event Procedure below. It is the final bit of code to complete stReportFilterCriteria that I am missing. Is it something to do with the wya the date is stored and the way it is displayed? CourseMotivateDate is stored as a ShortDate data type.

    Code:
    Private Sub CompletedCourses_Click()
    On Error GoTo Err_CompletedCourses_Click
    
        Dim stDocName As String
        Dim stReportFilterCriteria As String
    
        stDocName = "Courses"
        
        stReportFilterCriteria = "[CourseMotivateDate] < " & "DATE COMPARISON"
        Debug.Print stReportFilterCriteria
        
        DoCmd.OpenReport stDocName, acPreview, , stReportFilterCriteria
    
    Exit_CompletedCourses_Click:
        Exit Sub
    
    Err_CompletedCourses_Click:
        MsgBox Err.Description
        Resume Exit_CompletedCourses_Click
        
    End Sub

  2. #2
    Join Date
    Apr 2005
    Posts
    7
    OK - the solution for this was so annoyingly simple in the end. It came to me in one of those "Man, I'm such a dumba$$" moments.

    Basically, when defining stReportFilterCriteria I needed to use the following:
    Code:
    stReportFilterCriteria = "[CourseMotivateDate] < #" & Date & "#"
    As you can see, the vital items I was missing were the hashes (#).


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •