Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2008

Tip: Looking for answers? Try searching our database.

triggering formfield formatting

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Eric - 03 Jan 2008 04:40 GMT
I have a legal document set up as protected for filling out forms, and some
of the field forms have formatting applied to dates & currencies. When I
populate the document programmatically, the field formats I need
aren't applied until I manually tab through the doc. I tried the code below
but it doesn't do the trick.

TIA,
Eric

Private Sub TabThruForm(doc As Word.Document)
   Dim k As Integer
   Dim frmFlds As Word.FormFields
   Set frmFlds = doc.FormFields
   For k = 1 To frmFlds.Count
       If k <> frmFlds.Count Then frmFlds(k).Next.Select
   Next k
   frmFlds(1).Select
End Sub
Doug Robbins - Word MVP - 03 Jan 2008 08:41 GMT
Why not use the Format() function to format the data that is being inserted
as the .Result of the formfield.

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

>I have a legal document set up as protected for filling out forms, and some
> of the field forms have formatting applied to dates & currencies. When I
[quoted text clipped - 15 lines]
>    frmFlds(1).Select
> End Sub
Eric - 03 Jan 2008 11:38 GMT
I have different formats for different data. If I format the data first I
have to then know which piece of data I have, whereas now I am blissfully
ignorant of anything more than matching the data source (Excel) name to the
data target (Word bookmarked form field). The idea of formatting the data in
Excel isn't as appetizing either, as I don't always want the data in the
same format as when it is in the document.

Thanks,
Eric

> Why not use the Format() function to format the data that is being
> inserted as the .Result of the formfield.
[quoted text clipped - 19 lines]
>>    frmFlds(1).Select
>> End Sub
Doug Robbins - Word MVP - 04 Jan 2008 05:25 GMT
How are you populating the formfields?  Show use the code.

Sometimes a state of bliss will not get you what you want.

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

>I have different formats for different data. If I format the data first I
>have to then know which piece of data I have, whereas now I am blissfully
[quoted text clipped - 29 lines]
>>>    frmFlds(1).Select
>>> End Sub
Eric - 04 Jan 2008 05:55 GMT
Public Sub PopulateContractFormFields()
On Error GoTo PopulateContractFormFields_Error

   Dim frmFields As Word.FormFields
   Set frmFields = MContractDoc.ContractDocument.FormFields
   Dim bkMarks As Word.Bookmarks
   Set bkMarks = MContractDoc.ContractDocument.Bookmarks
   Dim ff As Word.FormField
   Dim thisNamedRange As String
   Dim thisValue As Variant
   For Each ff In frmFields
       ' every bookmark name shoulld have a corresponding excel name as
well
       ' use bookmarks on errors from setting form field result with very
long text
       thisNamedRange = ff.Name
       If thisNamedRange = "" Then
           thisValue = Empty
       Else
           thisValue = ProjectData.Range(thisNamedRange)
           If IsEmpty(thisValue) Then
               thisValue = ""
           Else
               On Error Resume Next
               ff.result = thisValue
               bkMarks(thisNamedRange).Range.Fields(1).result.Text =
thisValue
               On Error GoTo 0
           End If
       End If
   Next ff

  On Error GoTo 0
  Set frmFields = Nothing
  Set bkMarks = Nothing
  Exit Sub

PopulateContractFormFields_Error:
   Stop
   Resume
End Sub

> How are you populating the formfields?  Show use the code.
>
[quoted text clipped - 34 lines]
>>>>    frmFlds(1).Select
>>>> End Sub
Eric - 04 Jan 2008 05:59 GMT
Doug

Philisophy aside, isn't there some way to trigger formfield formatting via
vba?

Thanks,
Eric

> How are you populating the formfields?  Show use the code.
>
[quoted text clipped - 34 lines]
>>>>    frmFlds(1).Select
>>>> End Sub
Doug Robbins - Word MVP - 04 Jan 2008 09:14 GMT
If I use the following code to populate a formfield with the bookmark name
of Text2 that is formatted as currency, the result is $100.00

With ActiveDocument
   .FormFields("Text2").Result = 100
End With

I am not sure why you are doing both

ff.result = thisValue

and

bkMarks(thisNamedRange).Range.Fields(1).result.Text = thisValue

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

> Doug
>
[quoted text clipped - 42 lines]
>>>>>    frmFlds(1).Select
>>>>> End Sub
Eric - 05 Jan 2008 02:18 GMT
Thank you!! This is what I was trying to accomplish, and now can do:

   If Len(thisValue) < 255 Then
   ' let Word doc field set format
       ff.result = thisValue
   Else
   ' avoid error (design flaw) that field.result gives on a string that's
too long
       bkMarks(thisNamedRange).Range.Fields(1).result.Text = thisValue
   End If

- Eric

> If I use the following code to populate a formfield with the bookmark name
> of Text2 that is formatted as currency, the result is $100.00
[quoted text clipped - 57 lines]
>>>>>>    frmFlds(1).Select
>>>>>> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.