RiddleMeThis
MIS
Im trying to get the date of the previous day as specified at code level (i have a form for each day of the week so it will change from form to form).
Basically I want a variable containing the date of the previous monday for example (but could be any day), including today, so if this is monday i want today's date not last monday's, if this is friday then i want last monday's date.
At the minute im using the following VBA code with errors:
Dim strdate As String
Select Case WeekdayName(Now())
Case vbMonday
Set strdate = Now()
Case vbTuesday
Set strdate = DateAdd("d", -2, Now())
Case vbWednesday
Set strdate = DateAdd("d", -3, Now())
Case vbThursday
Set strdate = DateAdd("d", -4, Now())
Case vbFriday
Set strdate = DateAdd("d", -5, Now())
Case vbSaturday
Set strdate = DateAdd("d", -6, Now())
Case vbSunday
Set strdate = DateAdd("d", -7, Now())
End Select
MsgBox "Monday = " & strdate, vbOKOnly, "Monday"
The error i get is:
Compile error
Object Required
and it points to strdate in the first case.
Any ideas? If i havent explained it well let me know
Basically I want a variable containing the date of the previous monday for example (but could be any day), including today, so if this is monday i want today's date not last monday's, if this is friday then i want last monday's date.
At the minute im using the following VBA code with errors:
Dim strdate As String
Select Case WeekdayName(Now())
Case vbMonday
Set strdate = Now()
Case vbTuesday
Set strdate = DateAdd("d", -2, Now())
Case vbWednesday
Set strdate = DateAdd("d", -3, Now())
Case vbThursday
Set strdate = DateAdd("d", -4, Now())
Case vbFriday
Set strdate = DateAdd("d", -5, Now())
Case vbSaturday
Set strdate = DateAdd("d", -6, Now())
Case vbSunday
Set strdate = DateAdd("d", -7, Now())
End Select
MsgBox "Monday = " & strdate, vbOKOnly, "Monday"
The error i get is:
Compile error
Object Required
and it points to strdate in the first case.
Any ideas? If i havent explained it well let me know