First day of the current month (1 Viewer)

Acke

Registered User.
Local time
Today, 20:26
Joined
Jul 1, 2006
Messages
158
How to set first day of the current month as default value to a text box?

I managed to get current day minus 1 month using:

= DateAdd("m";-1;Date())
 
Code:
Public Function FirstDayInMonth(Optional dtmDate As Date = 0) As Date
    ' Return the first day in the specified month.
    If dtmDate = 0 Then
        ' Did the you pass in a date? If not, use
        ' the current date.
        dtmDate = Date
    End If
    FirstDayInMonth = DateSerial(Year(dtmDate), _
     Month(dtmDate), 1)
End Function
 
Thank you michaeljryan!

I have to put first-day-of-month as default value for a control. After I make Public Function as per your advice, what should I write under the "default value" section?
 
You don't need a public function just put

=Dateserial(year(date()), month(date()),1)

Brian
 
I agree that the public function may not be needed, but It is a nice piece of code to have just in case you need it later.
 
There is lots of code about that might be useful later but we need to answer the question asked.

Brian
 

Users who are viewing this thread

Back
Top Bottom