Results 1 to 3 of 3
  1. #1
    soco3594 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2015
    Location
    Australia
    Posts
    20

    Thumbs up Where Condition Problem - Dates

    Hi guys,

    I'm new to this forum and relatively new to Access (and VBA) so go easy on me... I've got a button set up on a form to print a report "rptProgressReport" based on a date field in the current record. The code is as follows:



    Code:
    Private Sub Command13_Click()
    
    DoCmd.RunCommand acCmdSaveRecord
    
    Dim strDocName As String
    Dim strWhere As String
        strDocName = "rptProgressReport"
        strWhere = "[ReportDate]= # " & Me!ReportDate & " # "
        DoCmd.OpenReport strDocName, acPreview, , strWhere
        
    DoCmd.Close acForm, "frmProgressReport", acSaveYes
    
    End Sub
    So basically it saves the current record, opens a report based on the "ReportDate" field in the current record, then closes the form. For some reason, the code doesn't like single digit dates i.e. 02-Nov-15 or 08-Dec-15. It works fine for all other dates (e.g. 25-Oct-15 etc.).

    Any ideas as to whether my code is lacking, or whether it could be a formatting issue? I have cleared all formatting in my source tables but not having any luck.

    Thanks in advance

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    The date structure is not Access/U.S. standard. That might be causing issue. Review http://allenbrowne.com/ser-36.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    soco3594 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2015
    Location
    Australia
    Posts
    20
    Quote Originally Posted by June7 View Post
    The date structure is not Access/U.S. standard. That might be causing issue. Review http://allenbrowne.com/ser-36.html
    Thanks! Got it working. For the record, it was a formatting issue. This is the final code:

    Code:
    Private Sub Command13_Click()
    DoCmd.RunCommand acCmdSaveRecord
    Dim strDocName As String
    Dim strWhere As String
        strDocName = "rptProgressReport"
        strWhere = "[ReportDate]= #" & Format(Me.ReportDate, "mm\/dd\/yyyy") & "#"
            
        DoCmd.OpenReport strDocName, acPreview, , strWhere
        
    DoCmd.Close acForm, "frmProgressReport", acSaveYes
    End Sub
    Thanks again

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

Similar Threads

  1. Replies: 4
    Last Post: 01-12-2015, 12:07 AM
  2. Query with many criteria (Dates, Condition, etc)
    By soldat452002 in forum Queries
    Replies: 5
    Last Post: 06-25-2014, 05:01 PM
  3. docmd.open form between dates condition
    By Ruegen in forum Programming
    Replies: 6
    Last Post: 09-22-2013, 11:23 PM
  4. Problem with adding dates
    By winterh in forum Access
    Replies: 1
    Last Post: 05-23-2012, 04:27 PM
  5. Between Dates Report Problem
    By aamer in forum Access
    Replies: 4
    Last Post: 12-02-2010, 01:00 PM

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