Results 1 to 5 of 5
  1. #1
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368

    Date minus zeven days, How hard can it be ?

    The code below works and deletes records that are older then two years from the tblWaarschuwingen table.

    Code:
    Dim dteExpiry As Date
    Dim strSQLDelete As String
    
    
    dteExpiry = DateAdd("yyyy", -2, Date)
    
    
    strSQLDelete = "DELETE from tblWaarschuwingen WHERE tblWaarschuwingen.datum2 <= #" & dteExpiry & "#;"
    DoCmd.RunSQL strSQLDelete
    If i try to do exaclty the same on another table but then date minus seven days, it fails !

    Code:
    Dim dteExpiry2 As Date
    Dim strSQLDelete2 As String
    
    
    dteExpiry2 = DateAdd("d", -7, Date)
    
    
    strSQLDelete2 = "DELETE from tblBlauweKaart WHERE tblBlauweKaart.Kaart_tot <= #" & dteExpiry2 & "#;"
    DoCmd.RunSQL strSQLDelete2
    What am i missing here ?

  2. #2
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    It seems dteExpiry2 returns a time rather then a date 0:00:00
    But i cant see why as im dimensioning dteExpiry2 as date

    And when i use the
    DateAdd("yyyy", -2, Date) it returns the right value.

    Im going berserk !

  3. #3
    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,847
    These work for me aCC2010

    ?DateAdd("d", -7, Date)
    01/11/2014
    ?Date
    08/11/2014

    What exactly is this
    tblBlauweKaart.Kaart_tot
    and how is it defined/dimmed?

  4. #4
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    I have aCC2010 as well.

    The translation of Blauwe kaart is blue card.
    And Kaart_tot means "Card untill"
    So the data in the field is the date the card is valid.

    Its so strange that if i code the date minus two years all goes well, and when i put date minus zeven days it doesnt work.
    While i am certain that the code im using DateAdd("d", -7, Date) is valid

    The field in the table is a date/time field

  5. #5
    thebigthing313 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    119
    It seems dteExpiry2 returns a time rather then a date 0:00:00
    But i cant see why as im dimensioning dteExpiry2 as date
    The Date datatype includes time in it as a decimal. Getting 0:00:00 just means that dteExpiry2 is set to 0.

    As for what you're missing, I'm not entirely sure.

    ?DateAdd("d", -7, Date) in the immediate window works for me.

    Alternatively, you can just do Date - 7.

    Code:
    dteExpiry2 = Date - 7

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

Similar Threads

  1. Replies: 5
    Last Post: 07-01-2014, 02:28 PM
  2. Replies: 1
    Last Post: 02-12-2013, 03:48 AM
  3. Replies: 8
    Last Post: 10-20-2012, 11:25 AM
  4. minus date wise sales a=n?
    By alex_raju in forum Access
    Replies: 1
    Last Post: 07-30-2011, 01:23 PM
  5. Date Add 26 weeks minus 1 day
    By ker9 in forum Queries
    Replies: 3
    Last Post: 07-26-2011, 01:20 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