473,466 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to you pass variables in the BeforeUpdate and AfterUpdate of a form field?

68 New Member
Hi!
Scenario:
'frmQuantity' has 2 fields: 'Quantity' and 'Change'. 'Quantity' is a number that is populated from a table. 'Change' is a % that starts out 0.00% and is only updated when 'Quantity' is changed.

How do I get the 'Change' field to show the % change of the 'Quantity' field?

I would like to get the 'Quantity' value by using BeforeUpdate, then AfterUpdate, then subtract the 2. I don't know how to make this happen.

I would appreciate any help.
thanks!!


.
Apr 6 '07 #1
6 3881
Rabbit
12,516 Recognized Expert Moderator MVP
Use a global variable to store the value.
Apr 6 '07 #2
dk4300
68 New Member
Use a global variable to store the value.
Could you please give me an example of how to do this?
Thank you!
Apr 7 '07 #3
Rabbit
12,516 Recognized Expert Moderator MVP
You would just Dim the variable at the top where the option statements go. Then you can use it like any other variable. But it keeps its value through the life of the form.
Apr 7 '07 #4
dk4300
68 New Member
I really appreciate you looking at this! Your last post really helped because I didn't know that the variables would save to the form like that. I'm making progress, but for some reason my BeforeUpdate is pulling the AfterUpdate number (which means it always calculates the sum as 0). Do you see what's still wrong with this?
Thanks!!

Option Compare Database
Dim dblBeforeQTY As Double
Dim dblAfterQTY As Double
Dim dblChange As Double

Private Sub QTY_BeforeUpdate(Cancel As Integer)
dblBeforeQTY = Me!QTY
End Sub

Private Sub QTY_AfterUpdate()

dblAfterQTY = Me!QTY
FindChange

End Sub

Function FindChange()

dblChange = dblAfterQTY - dblBeforeQTY
Me.Change = dblChange

End Function
Apr 7 '07 #5
Rabbit
12,516 Recognized Expert Moderator MVP
Here's what's happening, the BeforeUpdate event occurs after the value is changed but before it is saved. So because it occurs after the value has changed, it won't know what the value was before it changed.

What you have to do is, when the form loads, assign the current value to a global variable. And in the after update, calculate the change, and then store the new value to the global.
Apr 7 '07 #6
NeoPa
32,556 Recognized Expert Moderator MVP
There is also a property of most data holding controls called .OldValue. This will enable you to find the difference more easily I hope.
Apr 12 '07 #7

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

Similar topics

4
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a form with multiple pages on it. There is one text field on the third page of the form that I need the user to complete before leaving the form or moving...
0
by: Laertes | last post by:
Hi, I have the following simple(?) problem : lets say we have 3 yes/no fields. When I update field1 the afterupdate sub asks the user whether he wants to set field3 to 'yes' as well. I also...
4
by: bob bob via AccessMonster.com | last post by:
I'm sure this is a simple one. I have a combo box that, when its data is changed, will trigger a second form to open for input. If the operator declines input, I want the combo box to return to...
15
by: simonmarkjones | last post by:
I want to validate my form using a BeforeUpdate event. However now that i call my code with a beforeupdate it wont let me go to next or previous records. What code should i put in o allow me...
2
by: PC Datasheet | last post by:
In a form/subform I have an unbound combobox in the form header that sets the value of a field in the subform so that it does not have to be entered for each record. In the BeforeUpdate event of...
6
by: lorirobn | last post by:
Hi, I have a form with a continuous subform. I am working on putting validations in for the subform's required fields. Being somewhat new to Access (or rather, an antiquated mainframe...
6
by: tlyczko | last post by:
I have a BeforeUpdate where I need to ensure that no matter what, the first four fields on the form (one text box, 3 combo box lists) have data entered in them before the user closes the form or...
3
by: tlyczko | last post by:
Hello, I think what I'm asking for may not be possible, but I'll try anyway. I have MainForm with 3 subforms, one SubForm requires data entry, the other two don't (optional). MainForm has...
11
by: ChipR | last post by:
I have a generic AfterUpdate function applied to my 14 text boxes in a continuous subform, but I can't figure out the syntax to do BeforeUpdate with Cancel. Is this even possible? Private Sub...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.