Default date value

H

hotplate

Hello,
I am trying to make the default value the date of the first monday in
the month in an unbound box. Is there a way to do this?

Thanks,
James
 
A

Arvin Meyer [MVP]

Paste the following function into a standard module, and save it:


Function FirstMonday(Mo As Variant, Yr As Variant)
'Arvin Meyer 9/25/2006
Dim FM As Variant
FM = 10 - WeekDay(Mo & "/1/" & Yr)
If FM > 7 Then FM = FM - 7
FirstMonday = DateValue(Mo & "/" & str$(FM) & "/" & Yr)
End Function

Set the DefaultValue of the textbox to:

= FirstMonday(Month(Date()), Year(Date()))
 
V

Van T. Dinh

You can use the following function to obtain the date for the first Monday
of the current month / year.

========
Public Function fnFirstMondayOfCurrentMonth() As Date
Dim dteFirstOfMonth As Date
Dim intWeekDayOfFOM As Integer

dteFirstOfMonth = DateSerial(Year(Date), Month(Date), 1)
fnFirstMondayOfCurrentMonth = _
DateAdd("d", (9 - Weekday(dteFirstOfMonth)) Mod 7, dteFirstOfMonth)
End Function
========
 
Top