DateSerial Function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to have my ActiveX calendar control = the monday of the week that
a user fills out a form, but I am having trouble getting the value to be
selected. I have Dim'd a value and that seems to be preset with another day
and I can't figure out how it is getting it...is a redim statement need
somewhere? Here is my simple code.

Private Sub cmdCalendar_Click()

'Displays the calendar
Me.Calendar1.Visible = True

Dim strDay As String

strDay = DateSerial(Year(Now), Month(Now), Weekday(Now)) + 1
Me.Calendar1.Value = strDay

End Sub
 
perhaps you really want Day(Now()) instead of WeekDay(Now()). I believe
Weekday returns a value from 1 to 7 reflecting the day of the week (Sunday
to Saturday).

Also, if you just want tomorrow's date, you might take a look at
DateAdd("d",1,Date())
 
No, I want the WeekDay(Now)) portion of the statement because I want the date
selected to always be the Monday of the week someone fills out the form. I
think the statement is correct, but what I can't figure out is why it always
assigns 3/3/2006 (the first friday in the month) to strDay instead of
3/13/2006?
 
Jason said:
No, I want the WeekDay(Now)) portion of the statement because I want the date
selected to always be the Monday of the week someone fills out the form. I
think the statement is correct, but what I can't figure out is why it always
assigns 3/3/2006 (the first friday in the month) to strDay instead of
3/13/2006?


Your logic is incorrect. Weekday() will never return anything except 1 through
7 regardless of what you supply as the input argument.

See if this gives you what you want...

DateSerial(Year(Date()), Month(Date()),
(Day(Date())-(Weekday(Date(),vbMonday)-1)))
 
Back
Top