jaaret
Instructor
- Jun 19, 2002
- 171
I'm attempting to write a function that returns the last day of the month for any given date. My current attempt is generating a type mismatch error.
Here's my attempt:
Function LastDayOfMonth(DateMonth As Date) As Date
Dim MonthStr As String
Dim YearStr As String
Dim MonthInt As Integer
MonthStr = Month(DateMonth)
YearStr = Year(DateMonth)
MonthInt = Month(DateMonth)
Select Case MonthInt
Case 1
LastDayOfMonth = "#" & MonthStr & "/31/" & YearStr & "#"
Case 2
LastDayOfMonth = "#" & MonthStr & "/28/" & YearStr & "#"
Etc...
When I change the function's first line to:
Function LastDayOfMonth(DateMonth As Date) As String
It returns the correct string, i.e: #12/31/2006#
But when I try:
Function LastDayOfMonth(DateMonth As Date) As Date
It errors.
Thanks in advance for the help,
Jaaret
Here's my attempt:
Function LastDayOfMonth(DateMonth As Date) As Date
Dim MonthStr As String
Dim YearStr As String
Dim MonthInt As Integer
MonthStr = Month(DateMonth)
YearStr = Year(DateMonth)
MonthInt = Month(DateMonth)
Select Case MonthInt
Case 1
LastDayOfMonth = "#" & MonthStr & "/31/" & YearStr & "#"
Case 2
LastDayOfMonth = "#" & MonthStr & "/28/" & YearStr & "#"
Etc...
When I change the function's first line to:
Function LastDayOfMonth(DateMonth As Date) As String
It returns the correct string, i.e: #12/31/2006#
But when I try:
Function LastDayOfMonth(DateMonth As Date) As Date
It errors.
Thanks in advance for the help,
Jaaret