View Full Version : Constants


JimLecocq
12-04-2007, 08:21 AM
I may be barking up the wrong tree here but I wanted to see if there is an easier solution. I am getting better with Access and VB but I still have a ways to go.

I have a database and in it there are columns (integers) that have to be multiplied by a factor, at this point one by .38 the other .18 and one by .17, these factors change from time to time. This occurs in several queries. I could mark all the queries and change the factors one at a time but I wondered if a constant would take care of the problem. I thought about running it from VB but I have had a problem getting that to work also. Any suggestions? The place where the problem occurs I have colored red as you can probably see. I guess what I am looking for is a way to change these factors all at one time probably calling them DM, MM, and PT. We used to use Excel and had a criteria workbook that all the other files referenced. All I had to do was change it in the criteria workbook. Below is just one of the simpler queries.

SELECT tblCallsbyDay.Date, tblCallsbyDay.DM, tblCallsbyDay.MM, tblCallsbyDay.PT, tblCallsbyDay.DM+tblCallsbyDay.MM+tblCallsbyDay.PT AS TotalCalls,

[tblCallsbyDay.DM]*0.37 AS DMGoal, [tblCallsbyDay.MM]*0.18 AS MMGoal, [tblCallsbyDay.PT]*0.17 AS PTGoal,

DMGoal+MMGoal+PTGoal AS CallsGoalDay

FROM tblCallsbyDay

GROUP BY tblCallsbyDay.Date, tblCallsbyDay.DM, tblCallsbyDay.MM, tblCallsbyDay.PT;

KenHigg
12-04-2007, 08:58 AM
I would save them in table. That way you can set up a form to change/maintain them. Then either use a domain function like dlookup() to use them or you could put their values in global variables when the application opens or when you change the values in the update form you created....

JimLecocq
12-04-2007, 09:48 AM
Most of this I understand and had done some thinking about. But what do you mean by adding them to Global Variables and how is that done?

KenHigg
12-04-2007, 09:50 AM
Once you have them set up in a table, create a new code module and delcare the variables and set them using dlookup().

Need a sample db?

JimLecocq
12-04-2007, 10:06 AM
I like samples. That would be great and very helpful.

KenHigg
12-04-2007, 10:19 AM
There is a query that uses the table2 and a dlookup() (which does not need to use a public var) and a form whch uses one in the on load event...

JimLecocq
12-04-2007, 10:53 AM
Ken,

Thanks a lot this will take me a long way in Access. I have done a lot over the last few months but this is a very big help.

KenHigg
12-04-2007, 10:57 AM
Glad to help -

boblarson
12-04-2007, 10:57 AM
And, another simple way would be to just have a hidden form that has that table as it's recordset and text boxes to display it's values and you can pull the info at any time while the database is open (and also not worry about those instances where variables might get reset).