Results 1 to 10 of 10
  1. #1
    hect1c is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2014
    Posts
    15

    Allen Brownes Limiting a Report to a Date Range tip

    Hi

    I followed Allen Brownes code in this Ms Access tip
    http://allenbrowne.com/casu-08.html

    However I keep getting an error, not sure what I need to do to fix this error. The line the error refers to is in bold below. Thank you for you help.

    Private Sub cmdPreview_Click()
    'On Error GoTo Err_Handler 'Remove the single quote from start of this line once you have it working.
    'Purpose: Filter a report to a date range.
    'Documentation: http://allenbrowne.com/casu-08.html
    'Note: Filter uses "less than the next day" in case the field has a time component.
    Dim strReport As String
    Dim strDateField As String
    Dim strWhere As String
    Dim lngView As Long
    Const strcJetDate = "\#mm\/dd\/yyyy\#" 'Do NOT change it to match your local settings.

    'DO set the values in the next 3 lines.


    strReport = "withDateCrossTabQueryUsingUnion" 'Put your report name in these quotes.
    strDateField = "[ActivityDate]" 'Put your field name in the square brackets in these quotes.
    lngView = acViewPreview 'Use acViewNormal to print instead of preview.

    'Build the filter string.
    If IsDate(Me.txtStartDate) Then
    strWhere = "(" & strDateField & " >= " & Format(Me.txtStartDate, strcJetDate) & ")"
    End If
    If IsDate(Me.txtEndDate) Then
    If strWhere <> vbNullString Then
    strWhere = strWhere & " AND "
    End If
    strWhere = strWhere & "(" & strDateField & " < " & Format(Me.txtEndDate + 1, strcJetDate) & ")"
    End If

    'Close the report if already open: otherwise it won't filter properly.
    If CurrentProject.AllReports(strReport).IsLoaded Then
    DoCmd.Close acReport, strReport
    End If

    'Open the report.
    Debug.Print strWhere 'Remove the single quote from the start of this line for debugging purposes.
    DoCmd.OpenReport strReport, lngView, , strWhere
    Exit_Handler:
    Exit Sub
    Err_Handler:
    If Err.Number <> 2501 Then
    MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "Cannot open report"
    End If
    Resume Exit_Handler
    End Sub

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    I have not tried that code but personally, I always use either a popup date range form or have the report itself ask for it.

  3. #3
    hect1c is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2014
    Posts
    15
    A pop up date range form! Have you got an example?

  4. #4
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Sure. I generally use my Main form with start and end dates. See this Example: http://ms-access-tips.blogspot.com/2...ogue-form.html

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Further to burrina's suggestions, please see Martin Green's site and example.

  6. #6
    hect1c is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2014
    Posts
    15
    Thank you all for your assitance, much appreciated.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    What is the exact error message?
    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.

  8. #8
    hect1c is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2014
    Posts
    15
    After reading through the tips I received, I went through the code and found a variable not declared and an extra comma. The dates and the function work well from the form but when I run the report from inside the report design the dates do not work and show an error message. This additional problem is not really a concern because I would be running the reports from the form not through the report design. It could be the way I have set it up.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Something in the report is dependent on the form. If the form is not open the report has issues.

    This is resolved?
    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.

  10. #10
    hect1c is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2014
    Posts
    15
    Yes it is thank you!

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

Similar Threads

  1. Replies: 21
    Last Post: 04-29-2015, 11:57 PM
  2. Allen Brownes Inventory code
    By bbrazeau in forum Programming
    Replies: 4
    Last Post: 09-11-2013, 09:56 AM
  3. Date Range Report
    By seth.murphine in forum Reports
    Replies: 3
    Last Post: 04-23-2012, 02:46 PM
  4. Date Range Report with Multiple Date Fields
    By StevenCV in forum Reports
    Replies: 13
    Last Post: 02-29-2012, 08:29 AM
  5. Filter to a date range ala Allen Brown
    By kekawaka in forum Forms
    Replies: 2
    Last Post: 10-10-2011, 12:19 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