Solved Add end of the month date after date Update

theinviter

Registered User.
Local time
Today, 12:22
Joined
Aug 14, 2014
Messages
273
Dears;

i have a form whrere use add the 1st date of the month in "Date_From" , then i want "Date_To" to get last date of the month automatically,
can you guide me.

thanks
 
You could use a UDF. Something like:
Code:
Public Function LstDayMnth(InDate As Date) As Date
    LstDayMnth = DateSerial(Year(InDate), month(InDate) + 1, 0)
End Function
I take NO Credit for the code. It is just one of many very useful "date" functions which are in the following db which was made available, I believe, by Pat Hartman. Many thanks to Pat.
 

Attachments

i have a form whrere use add the 1st date of the month in "Date_From" , then i want "Date_To" to get last date of the month automatically,
can you guide me.
Code:
Dim iYear%, iMonth%, dDay As Date
    iYear = Year(Date)
    iMonth = Month(Date)

    dDay = DateSerial(iYear, iMonth, 1)
    Debug.Print "First date of the month: " & dDay
    
    dDay = DateSerial(iYear, iMonth + 1, 0)
    Debug.Print "Last date of the month: " & dDay
 
Here's a sample database with useful date functions. It includes the one offered by Bob

 

Users who are viewing this thread

Back
Top Bottom