[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Calculated Default Value

Posted on 2009-07-03
4
Medium Priority
?
295 Views
Last Modified: 2013-11-29
The goal is to provide a exchange rate as a default in a subform field based on 2 variables, the assigned currency of the client and the assigned currency of the transaction.

I am not sure how to approach this.

The exchange rates are updated daily and stored in the xrate table (tbl_xrate) witht the following fields.
[rate_div]: stores the exchange rate
[from_curr]: either CAD or USD
[to_curr: either USD or CAD
There is only 2 lines to this table (CAD - USD and USD-CAD).

[ccan_curr] stores the Currency of the client
[ast_currency] stores the Currency of the transaction
[ast_rate] stores the rate assigned by these 2 CAD/USD values as per the table.

I wrote this in plain english to give me an idea on how to do this but I dinf it veru complexe and I was wondering if I could do something simpler.  This code does not work, it is just a representation of where I am now.

Private Sub ast_currency_AfterUpdate()
' if ast_currency = "CAD" and form!frm_dda!ccan_curr = "CAD", me!ast_rate.DefaultValue = 1
' if ast_currency = "CAD" and form!frm_dda!ccan_curr = "USD", me!ast_rate.DefaultValue = rate_div where tbl_xrate.from_curr = "CAD"
' if ast_currency = "USD" and form!frm_dda!ccan_curr = "CAD", me!ast_rate.DefaultValue = rate_div where tbl_xrate.from_curr = "USD"
' if ast_currency = "USD" and form!frm_dda!ccan_curr = "USD", me!ast_rate.DefaultValue = 1

Any ideas on how to achieve this in a simpler manner?

Thanks in advance
0
Comment
Question by:YDagenais
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 85
ID: 24773442
So we're clear, a Default Value in Access is ONLY used with NEW records - that is, this would only come into play when you added a New record, and would not affect other existing records.

So your "xrate" table has only 2 RECORDS (we call them records in Access, not "lines") - one for the rate from CAD to USD, and another for USD to CAD?

What is your subform based on? Is it based on the second table you describe?
0
 

Author Comment

by:YDagenais
ID: 24773517
I understand that the default value is only for new records.. And you are right in your understanding of the xrate table.

The subform is based on a query from a table that would store the ast_currency field.

Hope this clarifies things.  I am looking  for a direction on how to do this.. Am I on the righ ttrack?
0
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 total points
ID: 24774114
Okay ... so when you build a NEW record in this subform, you'd need to determine the xrate ... and your subform would need information from the Parent form (I suppose) before it could do so?

So you must determine the exchange "route" (i.e. CAD > USD or USD > CAD) and then calculate this somehow?

Function AssignRate()

If Me.ast_Currency = Me.Parent.ccan_Cur Then
  '/the two Currencies selected are equap
  Me.ast_Rate = 1
Else
  '/currencies are NOT equal
  If Me.ast_Currency = "CAD" And Me.Parent.ccan_Cur = "UDS" Then
    Me.ast_Rate = DLookup("rate_div", "tbl_xrate", "from_curr='CAD'")
  Else
    Me.ast_rate = DLookup("rate_div", "tbl_xrate", "from_curr='USD'")
  End If
End If

This assumes we must "look" at the Parent for for the "ccan_Cur" value ...

' if ast_currency = "CAD" and form!frm_dda!ccan_curr = "CAD", me!ast_rate.DefaultValue = 1
' if ast_currency = "CAD" and form!frm_dda!ccan_curr = "USD", me!ast_rate.DefaultValue = rate_div where tbl_xrate.from_curr = "CAD"
' if ast_currency = "USD" and form!frm_dda!ccan_curr = "CAD", me!ast_rate.DefaultValue = rate_div where tbl_xrate.from_curr = "USD"
' if ast_currency = "USD" and form!frm_dda!ccan_curr = "USD", me!ast_rate.DefaultValue = 1
0
 

Author Comment

by:YDagenais
ID: 24785008
Thanks LSM.  That is what I was looking for.  A simpler way of approaching my problem.  Regardless i f there are bugs or not in the solution (probably not :):) , the concept is what I was looking for.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question