Converting string to currency

ombadboy

Registered User.
Local time
Yesterday, 20:39
Joined
Feb 9, 2007
Messages
30
Ok.. so ive been trying to convert a string to currency, but it seems its not working. Ive tried alot of workarounds, but still cant get it to work.

Dim tday As Date
Dim duedate1 As Date
Dim amount
Dim cur As Currency
Dim difference
tday = Date
duedate1 = [txtDueDate]
difference = Date - [txtDueDate]

If difference > 2 Then
amount = CStr(difference)
cur = CCur(amount * 2)
[PenApplied] = cur
Else
[PenApplied] = "Not applicable"
End If


Ive tried declaring "Cur" as string, ive tried directly using Ccur(Date - [txtDueDate]), ive tried loadsa stuff but still cant get it to work (as in display currency). The rest works ok

Thnx for ure help
 
Are you talking about Currency as a datatype or do you mean you want the filed to display the value Formated as Currency?

[PenApplied] = Format(cur, "£##,##0.00")

Peter
 
you want the filed to display the value Formated as Currency?
^^ that

ill have a go at the format and ill report 2morow

tnx

edit: lovely, worked :)
 
Last edited:
ahh.. still got problems with this piece of coding..

ive changed it slightly since i had unneeded variables, and changed txtDueDate to txtDateLoaned, but now it aint working.

Also, the previous piece of coding i has undead "got focus" but thats not actually where i want it to work. I need it to work as soon as the form opens up (before update) but it seems that isnt working either..


Private Sub PenApplied_BeforeUpdate(Cancel As Integer)
Dim amount
Dim difference
difference = Date - [txtDateLoaned]

If difference > 2 Then
[PenApplied] = Format(amount, "£##,##0.00")
Else
[PenApplied] = "Not applicable"
End If

End Sub
 
You probably want to use the forms current event, this will change it when the form opens and when you move to a new record.

in your code you have the variable amount but you have not set a value to it.

Peter
 
You probably want to use the forms current event, this will change it when the form opens and when you move to a new record.

how can i do that?
 
I need it to work as soon as the form opens up (before update) but it seems that isnt working either..
The BeforeUpdate of a form does not refer to when it is being opened or data entered. The BeforeUpdate fires just before the AfterUpdate event and gives you the opportunity to cancel any updates to the table which then occurs and then fires the AfterUpdate event.

What Peter was telling you was to select the code between the Private Sub PenApplied_BeforeUpdate(Cancel As Integer) and End Sub, cut it out (ctrl+X) and then use the drop down of events (top right of the code window) to select AfterUpdate and then paste the code in there.

Here is your code, with corrections:
Code:
Dim amount
Dim difference
difference = [B]Datediff("d", Me.txtDateLoaned, Date)[/B]

If difference > 2 Then
[PenApplied] = Format(amount, "£##,##0.00")
Else
[PenApplied] = "Not applicable"
End If

End Sub

And you should really declare your variables with a datatype instead of using
Dim difference

it would be
Dim difference As Integer

otherwise it is using a variant which takes up the most amount of memory as it has to allocate memory to handle any potential datatype.
 
Dear Friends,
I have designed a database which is similar to Northwind Sample db.

My problem is : I want to have the unit price in variable currencies (USD , Euro & YER) in the order form, after selecting the product. I have inserted an option to select the currency type on the main form. How could I achieve this function to print the report in multiple currencies (converted values) whenever needed. Of course, ex-rates should be updated time to time.

If you wish to see my sample db, I will forward a copy of it with required objects only.

Thanking you very much for your prompt action and response.
*David Ganesh*
 

Users who are viewing this thread

Back
Top Bottom