Can anyone point me in the right direction? I am a bit rusty with VBA (last used in Access 97)
I have the following code that, in principle, works. What it is doing is a calculation for output on a report. The problem is that it is using the first record in the database every time.
Where have I gone wrong?
David
Remember: You only know what you know
and - you don't know what you don't know!
I have the following code that, in principle, works. What it is doing is a calculation for output on a report. The problem is that it is using the first record in the database every time.
Code:
Function WarrantRenewalDate()
Const RenewDay = 31
Const RenewMonth = 3
Const RenewPeriod = 5
Dim rs As New ADODB.Recordset
Dim StartMonth, StartYear, CurrentYear, RenewYear As Integer
CurrentYear = Year(Now())
rs.Open "SELECT * from LeaderData", CurrentProject.Connection
If (rs!WarrantRenewDate) Then
StartMonth = Month(rs!WarrantRenewDate)
StartYear = Year(rs!WarrantRenewDate)
Else
StartMonth = Month(rs!LeaderStartDate)
StartYear = Year(rs!LeaderStartDate)
End If
If (StartMonth) > RenewMonth Then
StartYear = StartYear + 1
End If
RenewYear = Round(((CurrentYear - StartYear) / RenewPeriod) + 0.5)
If (RenewYear) = 0 Then
RenewYear = CurrentYear + RenewPeriod
Else
RenewYear = StartYear + (RenewYear * RenewPeriod)
End If
WarrantRenewalDate = DateSerial(RenewYear, RenewMonth, RenewDay)
End Function
Where have I gone wrong?
David
Remember: You only know what you know
and - you don't know what you don't know!