Varying Decimal Places in Report

mrcost

Registered User.
Local time
Today, 09:38
Joined
Oct 28, 2008
Messages
11
I have a 2003 Access report that is based on one query. The query has a calculated percentage that I want to display in the report. The user can choose the number of decimal places on a form that they want the percentage to round to in other calculations that are based on that percentage. I can't get the report to show the same number decimal places that the user selects on the form (either 0, 1, or 2).

Any help would be appreciated.

-Mrcost :cool:
 
i wouild think you want to use the either the on format or on print event, of the detail section.

so, as variables at the top of the report, have

const formattype = "00000000"
dim formatstrg as string


in the form's open event have

formatstrg = "0." & left(formattype,REQUIREDLENGTH) & "%"

(eg that should give you 0.0000% if requiredlength = 4
not sure where you store the requiredlength)


then in the detail's format or print event (not sure which) just

myfield = format(sourcedata,formatstrg)

should work.
--------
 
Thanks for the tips. I couldn't get it to work, so I was hoping you could help a bit more.

I have in the form On Open code:

Private Sub Form_Open(Cancel As Integer)
Const formattype = "00000000"
Dim formatstrg As String
formatstrg = "0." & Left(formattype, 4) & "%"
End Sub

And in the report On Format code:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
myfield = format(sourcedata, formatstrg)
End Sub

I always get confused on where to put form/field names and I was hoping you could help.

My form name is "frmEnterValues"

The field in the form to change the decimal places is named "Text44" and its control source is "Percentage" from table "tblsys".

The text box in the report that I want to change is "% Complete", currently formatted as Percent with 0 decimals.

Thanks a lot,

Mrcost :cool:
 

Users who are viewing this thread

Back
Top Bottom