Results 1 to 6 of 6
  1. #1
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108

    Limit Data to 12 months - Date range -HELP

    I have a form with 2 combo boxes( start range and end range)
    and an update button .
    This form will update the charts based on the Start_Range & End_Range values.

    Thus , I would like to limit the range to 12 months
    but I have no idea how to do it .

    Anyone can help with this ?
    Thanks in advance



    The code below is for the Update button
    Code:
    Private Sub cmd_Update_Click()
    Dim UpdateSQL As String
    Dim StartRange, EndRange As Date
    On Error GoTo ErrorHandler
        If (Me!cboStartRange.ListIndex = "-1" And cboEndRange.ListIndex = "-1") Or (Me!cboStartRange.ListIndex = "-1" Or cboEndRange.ListIndex = "-1") Then
        
        MsgBox "Please select Date Range!", vbOKOnly
        
        Me!cboStartRange.SetFocus
        
        Else
        StartRange = CDate(cboStartRange)
        EndRange = CDate(cboEndRange)
        UpdateSQL = "Update Setting Set Start_Range = '" & StartRange & "', End_Range = '" & EndRange & "' Where Type = 'SUMMARY_RANGE'"
        
        DoCmd.RunSQL UpdateSQL
        
        Me.Refresh
        
        Exit Sub
        End If
        
    ErrorHandlerExit:
        Exit Sub
        
    ErrorHandler:
        MsgBox "Error No: " & Err.Number & " ;  Description: " & _
        Err.Description
    Resume ErrorHandlerExit
            
    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    On The form , once the StartDate is filled , auto fill the EndDate, with the AFTERUPDATE event,
    txtEndDate = dateAdd("m", 12, txtStartDate)

    then the SQL would be,
    update field from table where FldDate between forms!frmRpt!txtStartDate and forms!frmRpt!txtEndDate

    you don't need any code, just the SQL above in a query and the form. No code.

  3. #3
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,426
    you don't even need the txtEndDate field on your form unless you have good reason, you sql would just be

    ...
    where FldDate between forms!frmRpt!txtStartDate and dateadd("y",1,forms!frmRpt!txtStartDate)

  4. #4
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    So it will auto display 12 months data ?

    And then I'm not gonna use this line anymore
    Code:
    UpdateSQL = "Update Setting Set Start_Range = '" & StartRange & "', End_Range = '" & EndRange & "' Where Type = 'SUMMARY_RANGE'"
    ?

  5. #5
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    I need txtEndDate when I wanna view certain amount of data ( I only want to view 3 or 4 months data)

  6. #6
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,426
    not sure if you are asking Ranman or myself - but yes, setting the end date 12 months or 1 year from start date will display 12 months data. If you want different periods, then Ranmans code is more appropriate

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

Similar Threads

  1. Replies: 4
    Last Post: 11-20-2018, 11:57 PM
  2. Limit chart to date range , Chart isnt updating .
    By fluffyvampirekitten in forum Access
    Replies: 5
    Last Post: 06-30-2015, 12:27 AM
  3. Get data - 3 months to Date
    By Shilabrow in forum Queries
    Replies: 3
    Last Post: 06-23-2014, 12:04 PM
  4. Replies: 3
    Last Post: 02-23-2014, 02:06 PM
  5. Limit report to a range of dates
    By nevets in forum Reports
    Replies: 2
    Last Post: 03-03-2012, 07:13 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