Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
Silena K-K Silena K-K is offline
external usenet poster
 
Posts: 11
Default Delete unused form fields

Hi there

I have the following text box form fields set for a report heading:

[Test Method] of [Active] in [Product], [Strength] [Dosage]

The report heading is centred. When all the fields are entered the heading
centers correctly on the page, however, if I do not have data for the
[Strength] or [Dosage] fields, because the field markers remain in the
heading, the heading becomes off-centre, even though the fields do not print.

How can I correct this?
Thanks, Silena
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Delete unused form fields

I take it that these are text form fields in a protected form? Inevitably
the fields and the spacing between them will occupy a particular amount of
space that will be reflected in their alignment as long as they are present.
The best answer is not to use the form fields for this purpose. Ideally I
would suggest a Userform to collect the data and write it into the heading
then, if necessary, protect the form - For the basics, see Word MVP FAQ -
Userforms
http://word.mvps.org/FAQs/Userforms.htm

for a more in depth explanation, see
http://gregmaxey.mvps.org/Create_and...a_UserForm.htm

However, it could also be done less elegantly with a macro run on exit from
the Product field to question whether the extra heading parts are required
and to add them if necessary, thus maintaining the alignment. The following
macro is run on exit from the 'Product' form field, and assumes that the
field is Text3. Everything else from the line should be removed. On exit
from the Product field, the macro prompts for content for the two now
removed fields and depending what is entered adds the result to the end of
the heading line. The macro is then removed from the field and the next form
field is selected. If you require the information from what was a field and
is now text to be reproduced elsewhere in the document, you can add the code
to the macro to apply the results of the two input boxes wherever you
require it.
http://www.gmayor.com/installing_macro.htm

Sub AddStrengthAndDosage()
Dim sStr As String
Dim sDos As String
Dim sRes As String
Dim oRng As Range
Dim bProtected As Boolean
Dim fCount As Long

sStr = InputBox("Enter strength if relevant", "Heading")
sDos = InputBox("Enter dosage if relevant", "Heading")
If Len(sStr) + Len(sDos) 0 Then
'Unprotect the file
If ActiveDocument.ProtectionType wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText ", "
If sStr "" Then Selection.TypeText sStr
If sDos "" And sStr "" Then
Selection.TypeText " "
End If
Selection.TypeText sDos
'Note Text3 here represents the field from which the macro
'is run i.e. the 'Product' field. Change the Text3
'to reflect the true name of the field (in three places)
sRes = ActiveDocument.FormFields("Text3").Result
ActiveDocument.FormFields("Text3").Select
With Dialogs(wdDialogFormFieldOptions)
.Exit = "" 'and remove the exit macro
.Execute 'apply the changes
'but note that this clears the value from the cell
End With
'So restore the value
ActiveDocument.FormFields("Text3").Result = sRes
'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, _
NoReset:=True, _
Password:=""
End If
End If
End Sub



Silena K-K wrote:
Hi there

I have the following text box form fields set for a report heading:

[Test Method] of [Active] in [Product], [Strength] [Dosage]

The report heading is centred. When all the fields are entered the
heading centers correctly on the page, however, if I do not have data
for the [Strength] or [Dosage] fields, because the field markers
remain in the heading, the heading becomes off-centre, even though
the fields do not print.

How can I correct this?
Thanks, Silena



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to delete unused styles - Macro? Bothell writer Microsoft Word Help 7 February 29th 08 10:28 AM
Printing UNUSED fields in forms Snoopygirl Microsoft Word Help 2 August 23rd 07 04:56 PM
How do I delete unused Heading formats from drop down menue patricia Microsoft Word Help 1 February 28th 07 12:35 AM
Word should let me automatically delete all unused styles. JohnThePresenter Microsoft Word Help 4 August 24th 06 04:59 PM
Delete unused columns on spreadsheet Needlewich Microsoft Word Help 1 May 17th 06 09:52 PM


All times are GMT +1. The time now is 07:38 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"