View Full Version : Report Problem


OldManRiver
08-12-2009, 10:15 AM
All,

Have a frustrating report problem. Have code of:Function RAmount()
HrsAmt = DLookup("trp_ham", "qryTIMshtS", "[trp_id]=" & Me![Row_ID])
MilAmt = DLookup("trp_mam", "qryTIMshtS", "[trp_id]=" & Me![Row_ID])
RAmount = HrsAmt + MilAmt
End Function
Function RCount()
RCount = DCount("trp_id", "qryTIMshtS")
End Function
Function RTotal()
HrsTot = DSum("trp_ham", "qryTIMshtS")
MilTot = DSum("trp_mam", "qryTIMshtS")
RTotal = HrsTot + MilTot
End FunctionThree fields are on the report with:

=RAmont()
=RCount()
=RTotal()

The middle function works, but the other 2 do not. Can not, for the life of me, figure out why one works and the others do not. I spent over 4 hours now using every possible combination I know to make these work.

HELP!!!!

OMR

pbaldy
08-12-2009, 11:11 AM
How do they not work (error, bad result, etc)? Have you stepped through the code to see if the DLookup's are returning values correctly? You haven't accounted for the possibility of a Null there. Are the variables declared anywhere?

OldManRiver
08-14-2009, 07:47 AM
All,

Found, contrary to normal math, that reports will not work if there is a null value anywhere. So code now reads:Public HrsAmt, MilAmt, HrsTot, MilTot
Function RAmount()
Dim FullAmount
FullAmount = 0
HrsAmt = DLookup("trp_ham", "qryTIMshtS", "[trp_id]=" & Me![Row_ID])
If HrsAmt > 0 Then FullAmount = FullAmount + HrsAmt
MilAmt = DLookup("trp_mam", "qryTIMshtS", "[trp_id]=" & Me![Row_ID])
If MilAmt > 0 Then FullAmount = FullAmount + MilAmt
RAmount = FullAmount
End Function
Function RCount()
RCount = DCount("trp_id", "qryTIMshtS")
End Function
Function RTotal()
HrsTot = DSum("trp_ham", "qryTIMshtS")
MilTot = DSum("trp_mam", "qryTIMshtS")
RTotal = HrsTot + MilTot
End FunctionWhich works.

Thanks all!!

OMR