Consulting

Results 1 to 4 of 4

Thread: Comparing Dates

  1. #1
    VBAX Newbie
    Joined
    Apr 2017
    Posts
    2
    Location

    Comparing Dates

    In my database i have to different date fields. What I want to do is create a vba code that would filter out any entry that has 2 dates that are in the same month. I tried to upload a sample of my data but i am currently getting an error.
    Last edited by mwieting; 04-07-2017 at 02:27 PM.

  2. #2
    Welcome!


    Where do you plan to use the VBA code?

    You normally filter records using a Query.

    To compare Month for any year use:

    Month([Date_1]) = Month([Date_2])

    To compare month and year try the following:

    (Month([Date_1]) = Month([Date_2])) and (Year([Date_1]) = Year([Date_2]))
    or

    Format([Date_1], "yyyymm") =  Format([Date_2], "yyyymm")


    On a form you could use:

    To compare month and year try the following:

    (Month(Me.[Date_1]) = Month(Me.[Date_2])) and (Year([Me.Date_1]) = Year(Me.[Date_2]))
    or

    Format(Me.[Date_1], "yyyymm") =  Format(Me.[Date_2], "yyyymm")
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  3. #3
    VBAX Newbie
    Joined
    Apr 2017
    Posts
    2
    Location
    Sorry I havent used access in awhile. error.jpg

  4. #4
    Without knowing more details of exactly what you are doing I can only give parts to help you. Not a working solution.

    What I posted about a query was only the criteria (Where) part of a query.

    A query would look something like

    Select [MyPrimaryKey], OPENDT, LASTDISBDT from [MyTableWithDates] where (Month(OPENDT) = Month(LASTDISBDT)) And (Year(OPENDT) = Year(LASTDISBDT))
    You will need to dd additional fields as needed. You may also need to add additional tables to get the two dates you want to compare.
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

Tags for this Thread

Posting Permissions

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