OK code as requested.
Basically I have a situation where we raise an invoice for support and we
want to spread the income from that support into the month in which support
is given.
So I am calculating how much support has still been charge but not yet used,
in terms of calendar months - defermonths and the second function returns 1
if the invoice covers a current month.
Any help you can offer would be gratefully received.
Thanks in advance.
Chris
Public Function DeferMonths(InvDate As Date, StartDate As Date, CurrDate As
Date, Duration As Integer) As Integer
Dim InvMonth
Dim StartMonth
Dim CurrMonth
Dim EndMonth
DeferMonths = 0
'Convert dates to month numbers
InvMonth = Year(InvDate) * 12 + Month(InvDate)
StartMonth = Year(StartDate) * 12 + Month(StartDate)
CurrMonth = Year(CurrDate) * 12 + Month(CurrDate)
EndMonth = StartMonth + Duration
' See if contract has finished and return zero
If CurrMonth >= EndMonth Then
DeferMonths = 0
GoTo Exit01
End If
' See if current month is before startmonth or invoice month
' and return zero
If CurrMonth < InvMonth Then
If CurrMonth < StartMonth Then
DeferMonths = 0
GoTo Exit01
End If
End If
'See if invoice and start months same
If InvMonth = StartMonth Then
DeferMonths = EndMonth - CurrMonth - 1
GoTo Exit01
End If
'See if Invoice month before start month
If InvMonth < StartMonth Then
If CurrMonth >= InvMonth Then
DeferMonths = EndMonth - CurrMonth - 1
If DeferMonths > Duration Then DeferMonths = Duration
GoTo Exit01
End If
End If
'See if invoice month after start month
If InvMonth > StartMonth Then
If StartMonth > CurrMonth Then
DeferMonths = 0
GoTo Exit01
End If
If InvMonth > CurrMonth Then
DeferMonths = CurrMonth - InvMonth
GoTo Exit01
End If
If CurrMonth >= StartMonth Then
DeferMonths = EndMonth - CurrMonth - 1
GoTo Exit01
End If
End If
Exit01:
End Function
Public Function CurrMonths(InvDate As Date, StartDate As Date, CurrDate As
Date, Duration As Integer) As Integer
Dim InvMonth As Integer
Dim StartMonth As Integer
Dim CurrMonth As Integer
Dim EndMonth As Integer
'Convert dates to month numbers
InvMonth = Year(InvDate) * 12 + Month(InvDate)
StartMonth = Year(StartDate) * 12 + Month(StartDate)
CurrMonth = Year(CurrDate) * 12 + Month(CurrDate)
EndMonth = StartMonth + Duration
' See if contract has finished and return zero
If CurrMonth >= EndMonth Then
CurrMonths = 0
GoTo Exit01
End If
' See if current month is before startmonth
' and return zero
If CurrMonth < StartMonth Then
CurrMonths = 0
GoTo Exit01
End If
CurrMonths = 1
Exit01:
End Function