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.
Printable View
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.
Welcome! :hi:
Where do you plan to use the VBA code?
You normally filter records using a Query.
To compare Month for any year use:
Code:Month([Date_1]) = Month([Date_2])
To compare month and year try the following:
orCode:(Month([Date_1]) = Month([Date_2])) and (Year([Date_1]) = Year([Date_2]))
Code:Format([Date_1], "yyyymm") = Format([Date_2], "yyyymm")
On a form you could use:
To compare month and year try the following:
orCode:(Month(Me.[Date_1]) = Month(Me.[Date_2])) and (Year([Me.Date_1]) = Year(Me.[Date_2]))
Code:Format(Me.[Date_1], "yyyymm") = Format(Me.[Date_2], "yyyymm")
Sorry I havent used access in awhile. Attachment 18896
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.Code:Select [MyPrimaryKey], OPENDT, LASTDISBDT from [MyTableWithDates] where (Month(OPENDT) = Month(LASTDISBDT)) And (Year(OPENDT) = Year(LASTDISBDT))