Converting currency

JeffreyDavid

Registered User.
Local time
Today, 18:09
Joined
Dec 23, 2003
Messages
63
I have a form with our customer information which includes currency, like US or CDN. I need the ExtPrice to check the txtExchangeRate and if 'CDN' then ExtPrice = txtExtPriceCdn, but if 'US', I need txtExtPriceUs = txtExchangeRate * ExtPrice. But I need to put this into a If Else statement.
Can anyone help?
 
Something like
Code:
Private Sub Form_Current()
    
    If Me.Currency = "US" Then
        Me.txtExtPriceUs = Me.txtExchangeRate * Me.ExtPrice
    Else
        Me.ExtPrice = Me.txtExtPriceCdn
    End If
    
End Sub
 
That doesn't seem to work. Maybe I should explain a little better. I have a main form with the customer information and a subform that has all of the order information. All of the fields I need to calculate on are on the main form. This is what I put in and it should work, but it doesn't:

Private Sub txtExtPriceTotal_AfterUpdate()

If Me.txtCurrency = "US" Then
Me.ExtPriceUs = Me.txtExchangeRate * Me.txtExtPriceTotal
Else
Me.ExtPriceUs = Me.txtExtPriceTotal
End If

End Sub
 
What exactly does it do then? Does it treat all currency as CDN or all as US?

Often times when I get stuck I use a MsgBox to tell me what is going on. Maybe txtCurrency is not being recognized as "US". Maybe it has trailing spaces.

You could try: Trim$(Me.txtCurrency)

Or if you want to see exactly what txtCurrency is, right before the "If" statement, insert:

MsgBox "XXX" & Me.txtCurrency & "XXX"

This will tell exactly what the string holds everytime it reaches the If statement and you will be able to tell if there are any leading or trailing spaces by using the "XXX".

You could also put a watch on the variable and do a step debug.
 
It was almost like the event wasn't firing. So I put the code into the LostFocus property of a trailing text box and it worked. The msgbox helped because it showed me when the event was firing.
Thanks RichO!
 
Did you try it in the Form_Current() event?
 
I tried the FormCurrent event and it only seem to fire when the form was first opened. It didn't fire when the text boxes had the data entered. It does fire when the text box loses focus.
 

Users who are viewing this thread

Back
Top Bottom