Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Oct 2014
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Access 2010 using DateAdd in VBA SQL string

    I can't find the answer to this problem after extensive searching the web.

    I am trying to update a module to add extra functionality to cater for GDPR.

    I have added:

    strSQL = "SELECT * FROM [" & tblName2 & "] WHERE PROCESSDAY<=DateAdd("yyyy",-5,Date())"

    and get a Compile error Expected: end of statement with the yyyy highlighted. Any ideas?

    Thanks

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    10,015
    Thanks
    429
    Thanked 1,611 Times in 1,460 Posts
    Mickelb,

    Try this:
    strSQL = "SELECT * FROM [" & tblName2 & "] WHERE PROCESSDAY<=" & DateAdd("yyyy",-5,Date())


    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    New Lounger
    Join Date
    Oct 2014
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thanks for the pointer.

    Actual code that works: strSQL = "SELECT * FROM [" & tblName2 & "] WHERE PROCESSDAY<=#" & DateAdd("yyyy",-5,Date())&"#"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •