?
Solved

Calculated Default Value

Posted on 2009-07-03
4
Medium Priority
?
293 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Suggested Courses

771 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