Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CDec in Report

Status
Not open for further replies.

JimWho

Vendor
Apr 2, 2002
16
0
0
CA
Why doesn't CDec work in my report? I have 2 subreports with numbers in them. I need to have the frequency between those 2 numbers. For example:
No. of Claims / No. of Vehicles Shipped.
5/1138 = 0.43%

With my code all of the fields provide the correct output with the exception of the numbers above. The output in my Access report for them is 50.00%. How do I get it to show 0.43%. I've tried using CDec in my code and Access does not like it. (Note 5 is derived with a query and 1138 is a number in a table and is a DOUBLE)

This is my code:
=[subREPORT Vehicle Count].Report!CCor/[subREPORT Volumes].Report!Volsub

Can someone please help?
Perplexed
JimWho?
 
Code:
=GetPercent([subREPORT Vehicle Count].Report!CCor,[subREPORT Volumes].Report!Volsub)


Function GetPercent(ByVal vNumerator As Variant, _
                    ByVal vDenominator As Variant) As String
On Error GoTo ErrHandler

  Dim n As Double
  Dim d As Double
  
  n = CDbl(vNumerator)
  d = CDbl(vDenominator)
  
  GetPercent = Format((n / d) * 100, "0.00\%")

ExitHere:
  Exit Function
ErrHandler:
  Debug.Print Err, Err.Description
  Resume ExitHere
End Function


VBSlammer
redinvader3walking.gif

[sleeping]Unemployed in Houston, Texas
 
Mr. VBSlammer
Thanks so much for responding. I inserted your code and it resolved one problem that being where I had an empty value in volumes so that now 2 from nothing results in nothing. I think that is correct, bosses may have another opinion?

It did not however resolve my problem of 5/1138 = 0.44%, it still shows up as 50.00%

Still perplexed in Toronto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top