I
Ian Baker
I have a report in an Artwork database that shows each piece of artwork and
all the valuations that have been done over the years. The report has:
Report Header
Page Header
ArtID Header
Detail
ArtID Footer
Page Footer
In the ArtID Footer I have 2 fields [ctlTotalIncrease] and [ctlPercentage]
that have to be calculated and inserted for each ArtID.
I have in the OnFormat property of the Detail the following code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
On Error GoTo HandleErr
Dim x As Long
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("SELECT tblValuation.ArtID, " & _
"tblValuation.ValuationAmount " & _
"FROM tblValuation " & _
"WHERE (((tblValuation.ArtID) = " & Me!ctlArtID & ")) " & _
"ORDER BY tblValuation.ValuationDate;", dbOpenDynaset)
x = ctlPurchasePrice
If x = 0 Then 'Art was donation so no purchase price - so use 1st
valuation
rst.MoveFirst
x = rst!ValuationAmount
rst.MoveLast
ctlTotalIncrease = rst!ValuationAmount - x
ctlPercent = (rst!ValuationAmount / x) - 1
lblTotalIncrease.Caption = "Total increase from 1st valuation"
Else 'Art was purchased so use purchase price
rst.MoveLast
ctlTotalIncrease = rst!ValuationAmount - x
ctlPercent = (rst!ValuationAmount / x) - 1
lblTotalIncrease.Caption = "Total increase from purchase"
End If
rst.Close
Set rst = Nothing
ExitHere:
Exit Sub
HandleErr:
StandardError Err, Err.Description, "frmValuation - Form_AfterUpdate"
Exit Sub
End Sub
My question is - is there a better way to do this?
For example if the SQL in the above code was hard stored as a query would it
run faster (but then how do I pass the ctlArtID parameter) or should the
code be placed somewhere else or am I better to make a temp table first????
Any comments are greatly appreciated
all the valuations that have been done over the years. The report has:
Report Header
Page Header
ArtID Header
Detail
ArtID Footer
Page Footer
In the ArtID Footer I have 2 fields [ctlTotalIncrease] and [ctlPercentage]
that have to be calculated and inserted for each ArtID.
I have in the OnFormat property of the Detail the following code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
On Error GoTo HandleErr
Dim x As Long
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("SELECT tblValuation.ArtID, " & _
"tblValuation.ValuationAmount " & _
"FROM tblValuation " & _
"WHERE (((tblValuation.ArtID) = " & Me!ctlArtID & ")) " & _
"ORDER BY tblValuation.ValuationDate;", dbOpenDynaset)
x = ctlPurchasePrice
If x = 0 Then 'Art was donation so no purchase price - so use 1st
valuation
rst.MoveFirst
x = rst!ValuationAmount
rst.MoveLast
ctlTotalIncrease = rst!ValuationAmount - x
ctlPercent = (rst!ValuationAmount / x) - 1
lblTotalIncrease.Caption = "Total increase from 1st valuation"
Else 'Art was purchased so use purchase price
rst.MoveLast
ctlTotalIncrease = rst!ValuationAmount - x
ctlPercent = (rst!ValuationAmount / x) - 1
lblTotalIncrease.Caption = "Total increase from purchase"
End If
rst.Close
Set rst = Nothing
ExitHere:
Exit Sub
HandleErr:
StandardError Err, Err.Description, "frmValuation - Form_AfterUpdate"
Exit Sub
End Sub
My question is - is there a better way to do this?
For example if the SQL in the above code was hard stored as a query would it
run faster (but then how do I pass the ctlArtID parameter) or should the
code be placed somewhere else or am I better to make a temp table first????
Any comments are greatly appreciated