Report Problem

OldManRiver

Registered User.
Local time
Today, 07:24
Joined
Jan 29, 2009
Messages
49
All,

Have a frustrating report problem. Have code of:
Code:
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 Function
Three 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
 
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?
 
What I found

All,

Found, contrary to normal math, that reports will not work if there is a null value anywhere. So code now reads:
Code:
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 Function
Which works.

Thanks all!!

OMR
 

Users who are viewing this thread

Back
Top Bottom