Results 1 to 9 of 9
  1. #1
    JTKrol is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    21

    Query to return all the birthdays for next month.

    I came up with the following string to do this but I keep getting an error...

    Next_months_Birthday: DateSerial(Year(Date())+IIf(Format(Date()),"mmdd") >Format([Month],"00") & Format([Day],"00"),1,0),[Month],[Day])

    The error I get is ....The expression you entered contains invalid syntax, or you need to enclose your text data in quotes. What am I missing here? I attached a screen shot hoping that will help.

    Thank you!!!
    Joe



    Attached Thumbnails Attached Thumbnails Access Birthday Query.jpg  

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Try:

    SELECT * FROM Employee_Info_Table WHERE Format(DOB, "YYYYMM") = Format(DateAdd("m", 1, Date()), "YYYYMM");
    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
    Mahendra1000 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2013
    Posts
    101
    Quote Originally Posted by JTKrol View Post

    Next_months_Birthday: DateSerial(Year(Date())+IIf(Format(Date()),"mmdd") >Format([Month],"00") & Format([Day],"00"),1,0),[Month],[Day])

    There's an extra open brackets ")" in your code. Have a look into it too.

  4. #4
    JTKrol is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    21

    Yep founds it...but now...

    Quote Originally Posted by Mahendra1000 View Post
    There's an extra open brackets ")" in your code. Have a look into it too.
    I took out the extra ) I removed the one after the 1,0 but now the error states that I have and Expression that contains the wrong number of arguments.

  5. #5
    JTKrol is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    21
    Quote Originally Posted by June7 View Post
    Try:

    SELECT * FROM Employee_Info_Table WHERE Format(DOB, "YYYYMM") = Format(DateAdd("m", 1, Date()), "YYYYMM");
    Will this work in December for January? My understanding was that by placing a 1 in the calculation you are essentially adding + 1 to a numerical date month which works fine until you get to December when it will add 12 + 1 returning 13 which will not give you January dates in December. Or was that something from an older version of Access that they fixed?

    Thanks
    Joe

  6. #6
    JTKrol is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    21
    Quote Originally Posted by June7 View Post
    Try:

    SELECT * FROM Employee_Info_Table WHERE Format(DOB, "YYYYMM") = Format(DateAdd("m", 1, Date()), "YYYYMM");
    I've tried putting that in but I'm getting syntax errors.

  7. #7
    JTKrol is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    21
    June7,

    I cleared up all the syntax problems but it is not working at all it runs the Query but does not return any values...

    Thank you for Trying to help.
    Joe

  8. #8
    JTKrol is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    21
    Quote Originally Posted by Mahendra1000 View Post
    There's an extra open brackets ")" in your code. Have a look into it too.
    What I am really trying to do is to use the system clock on the PC to have Access look at the current month and then look forward a month at the DOB field and pull out all the birthdays that have the same month as next month.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    My query should accomplish that. It works for me. Will work for December. Add 1 month returns January of next year.

    Are you sure there are records with DOB that meet the criteria?

    Post your exact attempted query.

    Provide sample data.
    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. Birthdays
    By comfygringo in forum Queries
    Replies: 3
    Last Post: 07-11-2013, 07:29 PM
  2. Access Query: Return Month Name and Year
    By PhatRam32 in forum Queries
    Replies: 7
    Last Post: 05-13-2013, 05:28 PM
  3. Replies: 5
    Last Post: 04-22-2013, 07:50 AM
  4. Month to return in Capital Letters
    By Alex Motilal in forum Queries
    Replies: 3
    Last Post: 01-09-2010, 05:19 AM
  5. Replies: 0
    Last Post: 08-04-2009, 08:51 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