Solved

Calculated Default Value

Posted on 2009-07-03
4
274 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
  • 2
  • 2
4 Comments
 
LVL 84
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 84

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MS SQL Bulk load data error 5 34
Correct ordering 16 48
After moving to webstite page stopped working 7 49
sql query Help 12 29
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now