Solved

Calculated Default Value

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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.

920 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

13 Experts available now in Live!

Get 1:1 Help Now