Results 1 to 6 of 6
  1. #1
    TrevorThielen is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2011
    Posts
    17

    Date filter only works on certain dates?!?

    I have one form with two date pickers and some buttons to open certain reports. It seems that if one of the dates is set to the 1st through 7th and 9th through 12th of a month, the filter just doesn't work at all, but any other dates and it works as it should. Has anyone else ever had this problem? Its in several spots of the same database. I have another form that just searches through the records on the form with an unbound date picker in the header and it does the same thing.

    Thanks in advance for any help!

    Heres some of the code I have, the rest is pretty similar:

    Private Sub Command30_Click()
    Dim db As Database
    Dim rs1 As Recordset
    Dim rs2 As Recordset
    Dim txtFirstDate As Date
    Dim txtLastDate As Date
    Dim strWhere As String
    Const conDateFormat = "\#mm\/dd\/yyyy\#"
    Set db = CurrentDb
    Set rs1 = db.OpenRecordset("Training")
    Set rs2 = db.OpenRecordset("TrainingCodes")

    If IsNull(Me.FirstDate) Or IsNull(Me.LastDate) Then
    MsgBox "Please Pick Both Dates!"
    Cancel = True
    Else
    If Me.LastDate > Me.FirstDate Then
    txtFirstDate = Me.FirstDate


    txtLastDate = Me.LastDate
    Else
    txtFirstDate = Me.LastDate
    txtLastDate = Me.FirstDate
    End If
    strWhere = "CourseDate >= #" & txtFirstDate & "# And CourseDate <= #" & txtLastDate & "#"
    DoCmd.OpenReport "TrainingOverview", acViewReport, , strWhere, acWindowNormal, OpenArgs


    End If
    Debug.Print Me.FirstDate
    Debug.Print Me.LastDate
    rs1.Close
    rs2.Close
    Set rs1 = Nothing
    Set rs2 = Nothing
    db.Close
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I suspect you forgot to use this:

    Const conDateFormat = "\#mm\/dd\/yyyy\#"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    TrevorThielen is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2011
    Posts
    17
    I was getting a Type Mismatch error when I tried it. So I took out the code. I'll revisit it now and see if I can't get it going.


    Thanks

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    TrevorThielen is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2011
    Posts
    17
    Got 'er figured! Thanks for your help!

    Lessons learned:
    1. When using Format(), change your variables to String type - hence the type mismatch errors!
    2. When using String type variables, change your WHERE clauses accordingly - then the filters actually work!

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    No problemo!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 21
    Last Post: 06-25-2013, 09:22 AM
  2. Filter Subform by Combo Box Dates
    By steve042 in forum Forms
    Replies: 14
    Last Post: 06-20-2013, 07:36 AM
  3. filter dsum between dates on a form
    By sdel_nevo in forum Forms
    Replies: 5
    Last Post: 06-03-2013, 03:07 PM
  4. Replies: 1
    Last Post: 06-21-2012, 07:58 PM
  5. How to filter dates using an apply filter code.
    By Jgreenfield in forum Reports
    Replies: 4
    Last Post: 11-15-2011, 01:38 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums