need some help

M

Mike

I have a template that a user can enter a dollar amount or percent. I want
the default to be a dollar amount but also except percents. The field does
not need to do a calculation.
How can i have the field default to dollar amount $ but also except a
percentage? %

I never written a macro or done any VBA in word what so ever, so i need some
help on this.

thx.
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Mike,

Run a macro containing the following code on exit from the formfield:

If Right(ActiveDocument.FormFields("Text1").Result, 1) <> "%" Then
ActiveDocument.FormFields("Text1").Result =
Format(ActiveDocument.FormFields("Text1").Result, "$#,##0.00")
End If

See the article “What do I do with macros sent to me by other newsgroup
readers

to help me out?” at:

http://word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
M

Mike

I can't get it to work.

Heres what i have
If Right(ActiveDocument.FormFields("AMOUNT_INS1").Result, 1) <> "%" Then
ActiveDocument.FormFields("AMOUNT_INS1").Result =
Format(ActiveDocument.FormFields("AMOUNT_INS1").Result, "0%")
Else
ActiveDocument.FormFields("AMOUNT_INS1").Result =
Format(ActiveDocument.FormFields("AMOUNT_INS1").Result, "$#,##0.00")
End If

End Sub

its still returning $0 if they enter a percent %5


"Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS"
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

The code that you are using is not what I suggested. My code works if the
last character entered into the formfield is a % which is the normal method
of writing a percentage, not %5. If the user does not include the % sign as
the last character in the formfield, the entry will be formatted as
currency.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
M

Mike

I have exactly what you suggested and trust me it helped me alot, but it
keeps going back to currency format.



"Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS"
 
M

Mike

should i have the default format be Text?
If i do that it appears to work, but i need it to default as currency and
allow percent and change to percent if one is entered.

thx again for your help, i'm new at this VBA coding

"Doug Robbins - Word MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS"
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Sorry Mike,

I posted an If ...End If construction. You have comeback with an If ...
Else... End If. That is not what I suggested. And yes, the formfield will
have to be a text formfield. It it is, and the use enters 5% it will
remain as 5%, if they enter 5, it will be formatted as $5.00

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top