Solved

Calculated Default Value

Posted on 2009-07-03
4
290 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 500 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

695 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