Results 1 to 6 of 6
  1. #1
    buster497 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2014
    Posts
    3

    Code to list 3 years record

    Hi,
    I am new to this forum.

    I have database which holds records dating back 4 years. I am trying to create a code to list all records into report older than 3 years from current date, every time I run the code. The problem is I cant get the date part to work (highlighted in red) . I have tried various date options.
    The [datepickedup] is the date.

    Can anyone help me on this Pls

    Thanks.

    Private Sub Form_Load()
    Dim intStore As Integer
    DoCmd.Maximize

    intStore = DCount("[ReferenceNo]", "[WasteCollectionRecord]", "[DatePickedup] and [datepickedup]< #" & Date & "#- 1095")

    'If count of uncomplete jobs is zero display switchboardor
    'Else display message box detailing amount of jobs
    'and give the user the option as to whether to view these or not.
    If intStore = 0 Then
    Exit Sub
    Else
    If MsgBox("You Have " & intStore & " Records In Your System Older Than 3 Years" & _
    vbCrLf & vbCrLf & "Would you like to see these now?", _
    vbYesNo, "Record Alert.......") = vbYes Then
    DoCmd.OpenReport "ArchiveReport", acViewReport, "", "", acDialog

    Else
    Exit Sub


    End If
    End If
    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Concatenation and # delimiter not needed when the parameter is Date() function (or Now() as well).

    intStore = DCount("[ReferenceNo]", "[WasteCollectionRecord]", "[DatePickedup] <= Date() - 1095")

    Simpler code structure:
    Code:
    Private Sub Form_Load()
    Dim intStore As Integer
    DoCmd.Maximize
    
    intStore = DCount("[ReferenceNo]", "[WasteCollectionRecord]", "[DatePickedup] <= Date() - 1095")
    'If count of uncomplete jobs is zero display switchboardor
    'Else display message box detailing amount of jobs
    'and give the user the option as to whether to view these or not.
    If intStore > 0 Then
            If MsgBox("You Have " & intStore & " Records In Your System Older Than 3 Years" & _
                        vbCrLf & vbCrLf & "Would you like to see these now?", _
                        vbYesNo, "Record Alert.......") = vbYes Then
                  DoCmd.OpenReport "ArchiveReport", acViewReport, "", "", acDialog
            End If
    End If
    End Sub
    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
    buster497 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2014
    Posts
    3

    Code not working

    Hi June7,

    Thank you for the reply. I have copied your suggested amendments but the code it is still not working. The code is listing all the records.

    Any reason why?.
    Thanks



    Quote Originally Posted by June7 View Post
    Concatenation and # delimiter not needed when the parameter is Date() function (or Now() as well).

    intStore = DCount("[ReferenceNo]", "[WasteCollectionRecord]", "[DatePickedup] <= Date() - 1095")

    Simpler code structure:
    Code:
    Private Sub Form_Load()
    Dim intStore As Integer
    DoCmd.Maximize
    
    intStore = DCount("[ReferenceNo]", "[WasteCollectionRecord]", "[DatePickedup] <= Date() - 1095")
    'If count of uncomplete jobs is zero display switchboardor
    'Else display message box detailing amount of jobs
    'and give the user the option as to whether to view these or not.
    If intStore > 0 Then
            If MsgBox("You Have " & intStore & " Records In Your System Older Than 3 Years" & _
                        vbCrLf & vbCrLf & "Would you like to see these now?", _
                        vbYesNo, "Record Alert.......") = vbYes Then
                  DoCmd.OpenReport "ArchiveReport", acViewReport, "", "", acDialog
            End If
    End If
    End Sub

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I tested syntax for the DCount with my data and it works.

    Have you step debugged? What is the value of intStore when the code runs? Is it correct? If it is then I expect the issue is with report design, not VBA.

    Refer to link at bottom of my post for debugging guidelines.
    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.

  5. #5
    buster497 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2014
    Posts
    3
    Hi June7.

    I have debugged the code and this did not highlight any problems.
    i have checked the design and i cant see anything obvious but i am no expert as i am still learning.
    I could attach the database but with being new here i don't know how to do this.



  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    To provide db follow instructions at bottom of my post.
    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.

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

Similar Threads

  1. Replies: 4
    Last Post: 07-03-2013, 10:02 AM
  2. Replies: 2
    Last Post: 06-28-2013, 12:58 PM
  3. Replies: 3
    Last Post: 08-26-2012, 10:04 PM
  4. Auto Delete record after 3 years?
    By maxx102 in forum Access
    Replies: 3
    Last Post: 06-01-2012, 08:55 PM
  5. Replies: 9
    Last Post: 09-16-2011, 03:52 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