We got told this morning that A97 is out and AccessXP(2002?) is in. I converted the mdb. Once the reference to DAO 3.6 was added, all seemed fine until I tried running a query that uses this function.
It works perfectly in A97 but bombs in AccessXP in that the recordset rstDAP doesn't have any records. Like I say the identical code works in 97. Any suggestions as to a workaround?
Code:
' Use this one in queries
Public Function DAmountApplied2(Dispos As String) As Currency
Dim db As DAO.Database
Dim rstDAP As DAO.Recordset
Dim qdfDAP As DAO.QueryDef
Dim DAP As Currency
Dim strSQL As String
Set db = CurrentDb()
Set qdfDAP = db.CreateQueryDef("")
strSQL = "SELECT ALLDISP.[Disposition Number], ALLDISP.[Date of 1st Lease], ALLDISP.[Effective Date], ALLDISP.[Area (Hectares)] " & _
"FROM ALLDISP " & _
"WHERE (((ALLDISP.[Current Status])=""ACTIVE"")) AND (((ALLDISP.[Disposition Number])= """ & Dispos & """))" & _
"ORDER BY ALLDISP.[Disposition Number]"
With qdfDAP
Set rstDAP = db.OpenRecordset(strSQL)
End With
With rstDAP
If .OpenRecordset.Fields(0).Value = Dispos Then
If Left(.Fields("Disposition Number"), 2) = "Q-" Or Left(.Fields("Disposition Number"), 2) = "ML" Then
If (Date - .Fields("Date of 1st Lease")) / 365.25 < 10# Then
DAP = .Fields("Area (Hectares)") * 25#
Else
DAP = .Fields("Area (Hectares)") * 50#
End If
If (Date - .Fields("Date of 1st Lease")) / 365.25 > 20# Then DAP = .Fields("Area (Hectares)") * 75#
ElseIf Left(.Fields("Disposition Number"), 2) = "CB" Or Left(.Fields("Disposition Number"), 2) = "S-" Then
If (Date - .Fields("Effective Date")) / 365.25 < 10# Then
DAP = .Fields("Area (Hectares)") * 12#
Else
DAP = .Fields("Area (Hectares)") * 25#
End If
ElseIf Left(.Fields("Disposition Number"), 2) = "MP" Then
If (Date - .Fields("Effective Date")) / 365.25 < 1# Then
DAP = .Fields("Area (Hectares)") * 1.25
Else
DAP = .Fields("Area (Hectares)") * 4#
End If
End If
End If
End With
rstDAP.Close
DAmountApplied2 = DAP
End Function