Results 1 to 7 of 7
  1. #1
    salonikije is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2017
    Location
    Montenegro
    Posts
    21

    Show the Report between two dates

    Dear,
    I'm almost done with my little app...



    But, I have to do one more thing and unfortunatelly, I got stuck....

    I have a simple app for managing state of drinks inventory. This app contains only one table, called "Artikal" in which I have some of fields.

    Now, I have the form called "Statistika", where I want to present cumulative list using reports... First report is list of all records, second is list of all records grouped by name of drink, and the third should be the report to show only records between two dates, which are selected by user...

    My idea is to have two date fields "From Date" and "To Date" on the "Statistika" form and when user chose the date range and click on the button on the right of them, it shows filtered report...

    The field in "Artikal" table which contains date is "Datum".


    I would appreciate if someone would help me solve this problem.


    Thnx in advance!
    Aleksandar

  2. #2
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by salonikije View Post
    My idea is to have two date fields "From Date" and "To Date" on the "Statistika" form and when user chose the date range and click on the button
    For clarity, you would not have "two date fields", you would have two unbound text boxes" for the dates.
    It is better to NOT have spaces in object names.


    What is the code in the button click?

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    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.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Maybe something like this:
    Code:
    Option Compare Database
    Option Explicit
    
    Private Sub cmdGetReport_Click()
        On Error GoTo Err_cmdGetReport_Click
    
        Dim stDocName As String
        Dim StartDate As Date
        Dim EndDate As Date
        Dim ServDate As String
        Const fmtDate = "\#mm\/dd\/yyyy\#"
    
    
        stDocName = "Your_Report_Name"  '<<<---change this to your report name
    
        'are both dates entered?
        If IsNull(tbFromDate) Or IsNull(tbToDate) Then
            MsgBox "You must enter both start and end dates."
            Me.tbFromDate.SetFocus
            Exit Sub
        ElseIf Me.tbFromDate > Me.tbToDate Then
            'is end date after start date?
            'automatic swapping
            StartDate = Me.tbToDate
            EndDate = Me.tbFromDate
    
            '        MsgBox "End date must be greater than Start date."
            '        Me.tbFromDate.SetFocus
            '        Exit Sub
        Else
            Me.Visible = False  '<<--hides form "Statistika"
            StartDate = Me.tbFromDate
            EndDate = Me.tbToDate
        End If
    
    
        ServDate = "[Datum]"   '<<--date field in table "Artikal"
        'open report
        DoCmd.OpenReport stDocName, acPreview, , _
                         Format(ServDate, fmtDate) & " Between " & _
                         Format(StartDate, fmtDate) & " And " & _
                         Format(EndDate, fmtDate)
    End If
    
    Exit_cmdGetReport_Click:
    Exit Sub
    
    Err_cmdGetReport_Click:
    MsgBox Err.Description
    Resume Exit_cmdGetReport_Click
    
    End Sub

  5. #5
    salonikije is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2017
    Location
    Montenegro
    Posts
    21
    Dear ssanfu, that's exactly what I mean... I use two unbound text boxes for the dates... and the code in the button click is now simple, just to open report on click... I'm looking for solution to put some definitions in the field "Where Condition" and here I have stuck

    I'll try to import code which you have sent... I'll inform you about results

  6. #6
    salonikije is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2017
    Location
    Montenegro
    Posts
    21
    Dear ssanfu, it works without any problems thank you so so so much!!!
    I appreciate this...

    Greetings from Montenegro!

  7. #7
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Glad to help. Good luck with your project...

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

Similar Threads

  1. Replies: 2
    Last Post: 09-19-2017, 11:31 AM
  2. criteria show only with dates
    By raffi in forum Queries
    Replies: 1
    Last Post: 12-27-2014, 11:44 AM
  3. Automatically show previous dates.
    By mbonning in forum Access
    Replies: 6
    Last Post: 09-12-2011, 12:12 PM
  4. Mixed dates - show only complete dates?
    By weeblesue in forum Queries
    Replies: 3
    Last Post: 10-27-2010, 02:15 PM
  5. Need report to show dates
    By Brian62 in forum Reports
    Replies: 2
    Last Post: 11-20-2009, 12:05 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