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.
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.
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:
or(Month([Date_1]) = Month([Date_2])) and (Year([Date_1]) = Year([Date_2]))
Format([Date_1], "yyyymm") = Format([Date_2], "yyyymm")
On a form you could use:
To compare month and year try the following:
or(Month(Me.[Date_1]) = Month(Me.[Date_2])) and (Year([Me.Date_1]) = Year(Me.[Date_2]))
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
Sorry I havent used access in awhile. error.jpg
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
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.Select [MyPrimaryKey], OPENDT, LASTDISBDT from [MyTableWithDates] where (Month(OPENDT) = Month(LASTDISBDT)) And (Year(OPENDT) = Year(LASTDISBDT))
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