First day of the current month (1 Viewer)

Acke

Registered User.
Local time
Today, 13:41
Joined
Jul 1, 2006
Messages
105
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())
 

michaeljryan78

Registered User.
Local time
Today, 07:41
Joined
Feb 2, 2011
Messages
165
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
 

Acke

Registered User.
Local time
Today, 13:41
Joined
Jul 1, 2006
Messages
105
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?
 

Brianwarnock

Retired
Local time
Today, 12:41
Joined
Jun 2, 2003
Messages
12,701
You don't need a public function just put

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

Brian
 

michaeljryan78

Registered User.
Local time
Today, 07:41
Joined
Feb 2, 2011
Messages
165
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.
 

Brianwarnock

Retired
Local time
Today, 12:41
Joined
Jun 2, 2003
Messages
12,701
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 (Users: 0, Guests: 1)

Top Bottom