Hi.
I want to have a userform that collects a whole dollar value. A
calculation is carried out using that whole dollar value then the
result are put into bookmarks.
The calculations are fine except I can't get the trailing .00 to
appear in the original dollar amount. I've tried the format()
function without any joy. Also I need to get the results of
calculations showing the cents.
I don't want to use Excel.
While still a rough WIP, I've pasted my code below.
'##################################
' Declare variables
'
Dim vGST As Currency ' I've tried single
Dim vAmount As Currency
Dim vTotal As Currency
Dim vBalance As Currency
' format (or try to the tbAmount value
'
vAmount = Format(tbAmount.Text, "###0.00")
' Calculate the tax and total due
'
vGST = Round(vAmount * 0.1, 2)
vTotal = Round(vAmount + vGST, 2)
' Format to show whole cents
'
vGST = Format(vGST, "###0.00")
vTotal = Format(vTotal, "###0.00")
' Put the form data into the Bookmarks
' I'd normally use a separate UpdateBookmark() function but
' this is for simplicity at this stage.
'
ActiveDocument.Bookmarks("Amount").Range.Text = vAmount
ActiveDocument.Bookmarks("GST").Range.Text = vGST
ActiveDocument.Bookmarks("Total").Range.Text = vTotal
ActiveDocument.Bookmarks("InvDate").Range.Text = tbInvDate.Text
ActiveDocument.Bookmarks("InvNo").Range.Text = tbInvNumber.Text
ActiveDocument.Bookmarks("Details").Range.Text = tbInvDetails.Text
'###########################################
Using a message box, vAmount show ony the whole dollar amount as
originally entered into the textbox.
vGST does not show the trailing 0 in the cents as does(n't) vTotal.
They do show the first decimal value i.e. 123.5
All assistance greatly appreciated as is constructive criticism of my
code.
Cheers
Shane
Doug Robbins - Word MVP - 30 Jul 2007 06:30 GMT
The format function returns a string. There is no need to be using it until
you actually insert the values into the document
ActiveDocument.Bookmarks("Amount").Range.Text = Format(vAmount, "#,##0.00")

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
> Hi.
>
[quoted text clipped - 56 lines]
> Cheers
> Shane
Shane - 31 Jul 2007 00:41 GMT
>The format function returns a string. There is no need to be using it until
>you actually insert the values into the document
>
>ActiveDocument.Bookmarks("Amount").Range.Text = Format(vAmount, "#,##0.00")
Thanks Doug. That worked fine.
Cheers