Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,859
    Ok, so here is what I HAD written expecting your two dates. That is now a little incorrect.
    Code:
    Dim Anfang As Date, Ende As Date
    
    
    Anfang = DateSerial(Year([Forms]![foLohnabrechnungMonat]![Startdatum](i)), Month([Forms]![foLohnabrechnungMonat]![Startdatum](i)) - 1, 1)
    Ende = DateSerial(Year([Forms]![foLohnabrechnungMonat]![Startdatum](i)), Month([Forms]![foLohnabrechnungMonat]![Startdatum](i)), 0)

    However we can now get away with just
    Code:
    Dim Anfang As Date, Ende As Date
    
    
    Anfang = DateSerial(Year(Date), Month(Date) - 1, 1)
    Ende = DateSerial(Year(Date), Month(Date), 0)
    Now in your query you use
    Code:
    Datum BETWEEN Anfang AND Ende
    or


    Code:
    Datum >= Anfang and Datum  < = Ende
    Or use the DateSerial() directly in the query, up to you.

    All the above written in Notepad BTW

    The key to all this is UNDERSTANDING the code/logic.

    HTH
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  2. #17
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    I think I confused the issue by using an array of type Date. It was just a short form way to process 4 different dates as examples.
    The purpose of the code was to show how to get the start and end dates of last month for any date.

    Sorry for the confusion.

    Welshgasman has it all under control.

  3. #18
    Akchayan is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Aug 2022
    Posts
    102
    Thank you very much for the help! You guys helped me alot especially Welshgasman. TY

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. query readings from current and previous month
    By JRCharlie in forum Access
    Replies: 14
    Last Post: 04-15-2018, 01:41 PM
  2. Replies: 2
    Last Post: 02-12-2015, 05:14 AM
  3. Replies: 1
    Last Post: 09-06-2014, 01:08 PM
  4. Replies: 2
    Last Post: 04-15-2014, 08:43 AM
  5. Select Month from previous selected year
    By k0enf0rNL in forum Access
    Replies: 1
    Last Post: 01-15-2014, 12:14 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