How find first date of month of last year after entering the first date of a month of this year

I want to populate a firm field with the first date of month of last year after entering the first date of a month of this year.  SO if I enter 10/1/2017 in the 1st field I want 10/1/2016 to populate the 2nd field.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fabrice LambertConsultingCommented:

You can use a combo of DateSerial, Year, Month and Day functions:
Public Sub test()
    Dim dt As Date
    Dim dtLastYear As Date
    dt = Now
    dtLastYear = DateSerial(Year(dt) - 1, Month(dt), Day(dt))
    Debug.Print dt
    Debug.Print dtLastYear
End Sub

Open in new window

crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
there is no need to store this, it can be calulated anytime.  Fabrice's function can be used (change Day(dt) to 1 for first day, or you can also put an equation into a Control Source or calculated field (without =) in a query:
   Control Source:
         =DateSerial(Year( [DateFieldname] ) - 1, Month( [DateFieldname] ), 1)

Open in new window

WHERE DateFieldname is the name of your date field.

DateSerial takes three arguments: year, month number, day number. Year is a function to get the year from a date. Month is a function to get the month number from a date.

when you refer to the first date of a month ... realize that can be calculated from any date by using DateSerial and simply using 1 for the Day parameter (argument)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.