S
Sunny
Following is my function in general module.
Function GetMonth(dDate As Date, cType As String) As Date
GetMonth = dDate - Day(dDate) + 1
If cType = "TYPE1" And Day(dDate) >= 25 Then
GetMonth = DateAdd("m", 1, GetMonth)
End If
If cType = "TYPE2" And Day(dDate) < 20 Then
GetMonth = DateAdd("m", -1, GetMonth)
End If
End Function
Now when I run this function in immidiate window
?GetMonth(date(),"TYPE1") 'returns 3/1/2004, which is expected.
but in immidiate window when I try following:
dt = date()
st = "TYPE1"
?GetMonth(dt,st) 'Which gives me error ByRef argument type mismatch
Can't I pass variable to the function? Or why this happens?
Function GetMonth(dDate As Date, cType As String) As Date
GetMonth = dDate - Day(dDate) + 1
If cType = "TYPE1" And Day(dDate) >= 25 Then
GetMonth = DateAdd("m", 1, GetMonth)
End If
If cType = "TYPE2" And Day(dDate) < 20 Then
GetMonth = DateAdd("m", -1, GetMonth)
End If
End Function
Now when I run this function in immidiate window
?GetMonth(date(),"TYPE1") 'returns 3/1/2004, which is expected.
but in immidiate window when I try following:
dt = date()
st = "TYPE1"
?GetMonth(dt,st) 'Which gives me error ByRef argument type mismatch
Can't I pass variable to the function? Or why this happens?