473,405 Members | 2,282 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,405 software developers and data experts.

Calculated field updated correctly with VBA after 2nd attempt

15
Hello,

I have the following calculated field:
=[quantity]*[pricePerPiece]*[currency].[column](1)

“Currency” is a comobox based on the following query:
SELECT DISTINCT tblCurrencyNames.CurrencyName, tblExchageRates.ExchangeRate
FROM tblCurrencyNames LEFT JOIN tblExchageRates ON tblCurrencyNames.CurrencyName = tblExchageRates.CurrencyName
WHERE (((tblExchageRates.OrderID)=[form]![OrderID]));

I have the following VBA statement in AfterUpdate event:
Forms!frmOrders!sfmorders.Form!CurrencyName.Requer y

Question:
Why is the calculated field updated with the correct value after entering value (in ExchangeRate field) 2nd time? After 1st attempt the calculated field is updated with a value which does not correspond to the formula.


Thank you for hints.

MS Access 2007

Marcin
Dec 8 '14 #1
4 1337
twinnyfo
3,653 Expert Mod 2GB
Please use code tags when posting code or queries.

For this line:
Expand|Select|Wrap|Line Numbers
  1. WHERE (((tblExchageRates.OrderID)=[form]![OrderID]));
I'm not sure how you will ever generate correct values in your combo box, as tblExchageRates.OrderID obviously refers to a PK and [form]![OrderID] seems to be pointing to a form.

It should be something more like this:

Expand|Select|Wrap|Line Numbers
  1. "WHERE (((tblExchageRates.OrderID)= " & Me.[OrderID] & "));"
(notice the quotes)

I don't know if that has anything to do with your direct problem. I can only assume that Forms!frmOrders!sfmorders.Form!CurrencyName is the calculated field?

The information seems a bit incomplete. Perhaps adding
Expand|Select|Wrap|Line Numbers
  1. Me.Refresh
before you find the value?
Dec 8 '14 #2
jforbes
1,107 Expert 1GB
Maybe call a .Recalc on your calculated field? Usually Access is good at determining when a field needs recalculated, but sometimes you need to help it out a little.

It looks like you are trying to create an Order with a CurrencyType option. In the past, I've stored the CurrencyType on the Order, then used a Query on the Order Lines table joined back to the Order (then joined to a CurrencyConversion table) to perform the Totals Calculations that take into account the Currency conversion. So you might get around this by moving your calculation into a Query instead of it all being done on your Forms. The advantages of this are that you can use the same query for Forms and Reports as well as there being only one place to modify (or troubleshoot) the calculation.
Dec 8 '14 #3
MarcinM
15
@jforbes
Yes, using a calculated field in a query is an interesting approach. However, my form is based on 3 tables (1 table on 1-side one, 2 tables on many-side) and when I add all the required fields the all the tables the query (and form) becomes read only. Is there a work around to make it editable?
Dec 12 '14 #4
jforbes
1,107 Expert 1GB
There are a couple easy ways to address this:
  • For inline values, use Unbound fields for the calculations then in the Forms OnCurrent Event use a Dlookup to set the value from the Query.
  • For totals, Create a SubForm based on the Query
Dec 12 '14 #5

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

Similar topics

14
by: Allen Browne | last post by:
Subform is based on a single-table query that contains a calculated field: Amount: Round(CCur(Nz(*,0)),2) Continuous subform displays this field in a text box named Amount. As user enters new...
2
by: Mark Kola | last post by:
I have ran into an interesting situation. I have a calculated field based on a combobox column that somtimes is not requerying when I change the combo box value. Combobox cboCustomer 2...
1
by: Yuki | last post by:
Thanks for taking the time to look at my problem. I keep getting a #Name error from a calculated field on a form. It is a text box field unbound. The calculation is very very simple yet I still...
2
by: hhathome | last post by:
In my report I have a calculated DateDiff Field, I also have a calculated count field. I'm trying to get a total of the DateDiff field and dividing it by the count field and I'm having problems --...
3
by: kelley.l.turner | last post by:
Hi all, I am very new to MS Access so please bear with me! I have created a simple calculated field in my data entry form, yet when I view my data table or try to generate a report based on...
5
by: Henrik | last post by:
The problem is (using MS Access 2003) I am unable to retrieve long strings (255 chars) from calculated fields through a recordset. The data takes the trip in three phases: 1. A custom public...
9
by: Haas C | last post by:
Hi all! Is there anyway I can override a value in a calculated field on a form? For example: I have a form which displays the following fields based on a query: Premium Due field has the...
5
by: CSmith | last post by:
I have a calculated field in a query, it calculates the # of days an employee has been employed using the following statement =datediff("d", , NOW()) by default. When an employee is terminated, I...
6
by: Steve67 | last post by:
Wonder if I can get someone’s help with a problem I am having on where to place an IF statement in VBE. I have created a form in Access 2003 that has an automatic calculated field. Basically you...
1
by: Greg (codepug | last post by:
Access 2000 Using a textbox of a single form, I created a calculated field. The following code is in the Control Source for this field: =IIf(=24,+(/),/ ) The numbers that are calculated are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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...
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
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,...

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.