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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiply Report Result Field By a Constant???

Status
Not open for further replies.

jasonp45

Programmer
Aug 23, 2001
212
US
I have a report based on a crosstab query that outputs something like this:

Field1 Field2 Field3
34 22 15

Now for some of my fields I need to multiply the result by a constant, and the constant differs from field to field. So if I want to multiply Field1 by, say 1.5, how do I do it within my report? I tried using the ExpressionBuilder but it didn't seem to do anything, and I'm not familiar with writing code within a report...don't know what the objects are. Any help greatly appreciated.
 
In your report in design view, select your detail band. Look under your property sheet in events and create one for on detail print then type code like:

Option Compare Database
Option Explicit
Private Const ACONSTANT As Long = 1.5

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
Me.TextSomething = [My Source] * ACONSTANT
End Sub

Hope this helps,
Rewdee
 
Create a table, lets call it tblMultiplier.
Create a field for each multiplier you need (make sure the field is "Number", and the size is single if you want to use decimals):
multiplier1
multiplier2
multiplier3

Now enter values in this table
multiplier1 = 1.5
multiplier2 = 2.5
multiplier3 = 3.5

Now lets say you want to multiply Field1 times multiplier1 (1.5)

In the control source for that field, put the following:

=[Field1] * DLookup("Multiplier1", "tblMultiplier")

Using a table allows you to change your multipliers without touching the report.


Jim Lunde
compugeeks@hotmail.com
Custom Application Development
 
Can you give an example of the expression you had problems with?

What part of the report did you have the control in? (Page Header, Detial, etc.)? I have had problems (I can't remember exactly) with expressions for controls in Footers.
 
The simplest thing to do is, as the source for the control where you want the product put =[Field1]*1.5.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top