473,386 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Using global variables in report calculation.

I have a global variable assigned in a module.
Expand|Select|Wrap|Line Numbers
  1. Public MyVar as Integer
Right before I open a report, I have the variable set.
Expand|Select|Wrap|Line Numbers
  1. MyVar= InputBox("Please enter the markup percentage for oursource work.")
  2. If IsNumeric(MyVar) Then
  3.     If MyVar>= 0 And MyVar< 300 Then
  4.         MsgBox ("Outsourced Markup is stored at " & MyVar& "%")
  5.     Else
  6.         MsgBox ("Please try again.")
  7.         Exit Sub
  8.     End If
  9. Else
  10.     MsgBox ("Please try again.")
  11.     Exit Sub
  12. End If
  13.  
  14. DoCmd.OpenReport "rptWorkScope", acViewPreview
In the report, i am using the value of the outsourced markup in a calculation in the control source of a reported feild (all outsourced markups are the same).

Expand|Select|Wrap|Line Numbers
  1. =cost1 * MyVar
This doesnt work. When the report opens it states "Enter Parameter Value"....MyVar

Is there a way around this. I tried putting a new field on the form (invisible) that was unbound, and in the On_Open setting
Expand|Select|Wrap|Line Numbers
  1. NewField = MyVar
and then in the control source of the calculation using
Expand|Select|Wrap|Line Numbers
  1. =cost1 * NewField
but that didnt work either....seems that the "NewField" isnt available yet in the on open event....
I also tried setting the parameter in the On Load event, but still no sucess. Is there a way to refer to the global variable in the calculation?
May 4 '11 #1
2 3782
ADezii
8,834 Expert 8TB
Try performing the Calculation, then assigning it to a Field on the Report in the Activate() Event, as in:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Activate()
  2.   Me![txtSomeField] = <Some Value> * MyVar
  3. End Sub
May 4 '11 #2
Thanks, I ended up going a different route. The "Activate" event seems to still fire after the calculations are run, so it still didnt work. In your example, I am still trying to use "TxtSomeField" in another calculation, and it cant find the value of "TxtSomeField" before doing the MyVar calculation.....sorry, that seems clear as mud now. But not to worry, it is running a different way.
May 9 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: sarmin kho | last post by:
Hi Pythoners, i have been using a lot of global variables in the python script i am working on. the global variables are shared and used by all various 'definitions' : def name (): global all...
1
by: mark4asp | last post by:
What are the best methods for using global constants and variables? I've noticed that many people put all global constants in a file and include that file on every page. This is the best way of...
17
by: MLH | last post by:
A97 Topic: If there is a way to preserve the values assigned to global variables when an untrapped runtime error occurs? I don't think there is, but I thought I'd ask. During development, I'm...
7
by: Michael | last post by:
Hi newsgroup, as the subject indicates I am looking for an advice using global variables. I am not if this problem is more about style then C. If its wrong in thi group, sorry. So I have a...
13
by: Sunil | last post by:
Hi all, I want to know how good or bad it is using global variables i.e advantages and disadvantages of using global variables. Sunil.
6
by: rlrcstr | last post by:
The DBA team at the office controls the naming conventions for the database structure, but their naming convention are rather tedious. So typically I create a global module that I use as a mapping...
3
by: frothpoker | last post by:
Guys, I'm sure this has been asked a million times but I can't seem to formulate a google search that returns what i'm looking for. I've go a dev and live environment. Currently the DB...
10
patjones
by: patjones | last post by:
Hi: I have two forms, frmVerifyUser and frmVerifyNewPassword. In the VB module for both forms, at the very top, I try to set a global variable like Public strNewPassword As String Option...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
1
by: Keith Hughitt | last post by:
Hi all, I was wondering if anyone had any suggestions for alternative ways for multiple objects to keep track of a single variable? Initially, I thought of just using a single (YUI) Custom event...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.