473,396 Members | 1,982 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,396 software developers and data experts.

Reference a variable and its SQL-based value in two procedures

15
I am using Access 2003 and need some guidance on the correct way to reference a variable in two different procedures when the variable's value is based on a SQL query.

The database form has a button that, when clicked, will send an email, summarizing in the subject line the $ amount sold so far for the day. This email may be sent several times per day as needed, depending on the pricing volume. Then at the end of the day when all the pricing has been processed, a different button sends a final email (to a larger group of folks) summarizing in the subject line the $ amount for the day plus some other information the midday update email didn't have.

The following code currently exists (and functions fine) in both procedures to create the value for the total $ amount priced during the day (dblPricingSum):

Expand|Select|Wrap|Line Numbers
  1. Dim dblPricingSum as Double
  2. dblPricingSum = CurrentProject.Connection.Execute("SELECT Nz(Round(Sum([Price]*[Quantity]),2),0) FROM DailyPricings WHERE ([PricingDate] = Date())")(0)
I then reference dblPricingSum in each email's subject string. However, because the summarizing $ amount is common to both emails, it seems logical to just declare and assign the variable once, then reference it in both procedures as needed. With some experimentation, I determined that if I were assigning a set value, I could declare dblPricingSum as a constant before the first procedure and reference it that way. However, because the variable value is a SQL query-based, I get an invalid outside procedure message if I try to go that route.

I've been largely learning Access and VB as I go so I have a lot of holes in my education. Any guidance would be very appreciated!
Aug 7 '08 #1
7 1654
NeoPa
32,556 Expert Mod 16PB
You lost me in the paragraph after the code :(

Does the value increase as the day progresses?

Where would you be trying to access the value from?
Aug 7 '08 #2
RachH
15
lol sorry!

The DailyPricings table stores pricing information as it occurs throughout the day so the SQL query I included just summarizes whatever the total $ amount is for the current day at the time the SQL query is run (by summing price * quantity for records with the current day's date). So the $ amount may or may not change during the day, depending on whether or not any pricings occur. I just want to be able to assign that $ amount to a variable and reference it in two different procedures.

Does that make any more sense?
Aug 8 '08 #3
NeoPa
32,556 Expert Mod 16PB
The question is :- How are these procedures connected?

If they are both invoked from the same piece of code then a Public variable would probably be adequate, but, depending on the thread of your code, you would set the value when you ran the first one so that the second one had it available.

I'm still a little confused as you already have code which seems to cover the basic concept. If there is anything much more complicated I can't see it. Possibly there is something you haven't mentioned?

If they are run independantly, of course, I can't see that it would be a safe process to assume the previously grabbed value is still valid.

Clearly it's possible my ramblings don't fit your situation, but if so either I've missed something you've posted or you've missed posting something.
Aug 8 '08 #4
RachH
15
My existing code works fine but since I reference that total $ amount (as determined by the SQL query) in both the procedure that sends the midday update email, as well as the procedure that sends the final end of day email, I had thought to simplify the overall code by only declaring and assigning the SQL query once (however, given the gaps in my education, thinking often gets me in trouble).

Basically, is there a way I can give a variable public scope and assign it to execute a SQL string to obtain its value each time it is referenced, but do all that outside of a procedure? Or do I have to repeat the assignment in each procedure that uses it because Access will only execute SQL queries inside procedures?
Aug 8 '08 #5
NeoPa
32,556 Expert Mod 16PB
Ah, perhaps you're talking about another procedure (function) which returns the value required, but doesn't involve repeating the code in both your existing procedures?
Aug 9 '08 #6
RachH
15
Actually, yup that should do it exactly. It's amazing how obvious the solution becomes when I stop trying to make VB follow my logic process and instead I try to follow VB's logic process! Thank you very much for helping me through that educational experience :-)
Aug 11 '08 #7
NeoPa
32,556 Expert Mod 16PB
It's been a pleasure Rach.

That Eureka Moment is so sweet isn't it :)
Aug 11 '08 #8

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

Similar topics

6
by: Randell D. | last post by:
Folks, I've asked this before but never got any response but its important and I thought I'd pitch it again (hopefully a bit clearer)... One can pass data from one function to another either...
2
by: Kench | last post by:
I was curious and playing with pointers and references to see what's different between them. Other than the obvious ones involving C++ syntax & things like references cannot be modified with...
2
by: Jim Red | last post by:
hello first of all, i know, there are no classes in javascript. but i will use that word for better understanding of my question. here we go. i have three classes and need a reference to the...
6
by: CFW | last post by:
References in Access and .mdb files have always been painful for me - just when I thought I was OK in an .mdb, I have a .adp I'm working on and I need to use Set db as CurrentDb - Constant "object...
2
by: Jake Barnes | last post by:
Using javascript closures to create singletons to ensure the survival of a reference to an HTML block when removeChild() may remove the last reference to the block and thus destory the block is...
14
by: junw2000 | last post by:
For example, int i = 5; int &r = i; Are i and r two different variables? Or do i and r occupy the same memory space? that means they are the same variable? Thanks.
51
by: Kuku | last post by:
What is the difference between a reference and a pointer?
7
by: pauldepstein | last post by:
#include <iostream> using namespace std; double & GetWeeklyHours() { double h = 46.50; double &hours = h; return hours; }...
3
by: sisqorap | last post by:
Hi all, I have this kind of warning and would like to have it solved: Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration...
3
by: shapper | last post by:
Hello, On an ASP.NET MVC project I am getting a list of Tags which names start with a string contained on the variable "q". Everything works fine if no Post is related to Tags. When there is...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.