|
|
| Next: Word 2007 page revision date |
| Author |
Message |
Shane External

Since: Jul 30, 2007 Posts: 2
|
Posted: Mon Jul 30, 2007 2:16 am Post subject: Textbox Value, Calculations, and Display with Decimals Archived from groups: microsoft>public>word>vba>userforms (more info?) |
|
|
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 |
|
| Back to top |
|
 |
Doug Robbins - Word MVP External

Since: Jul 14, 2006 Posts: 2538
|
Posted: Mon Jul 30, 2007 2:16 am Post subject: Re: Textbox Value, Calculations, and Display with Decimals [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
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")
--
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
"Shane" <write.it.TakeThisOut@-REMOVETHIS-westnet.com.au> wrote in message
news:e0qqa3pc9cgvd1qipcs5filrrjqvum18ov@4ax.com...
> 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 |
|
| Back to top |
|
 |
Shane External

Since: Jul 30, 2007 Posts: 2
|
Posted: Tue Jul 31, 2007 2:16 am Post subject: Re: Textbox Value, Calculations, and Display with Decimals [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
On Mon, 30 Jul 2007 15:30:59 +1000, "Doug Robbins - Word MVP"
<dkr.RemoveThis@REMOVECAPSmvps.org> wrote:
>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 |
|
| Back to top |
|
 |
|
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
| |
|
|