Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Userforms and Bookmark - Help Needed!

Status
Not open for further replies.

riffer28

IS-IT--Management
Feb 7, 2002
11
US
I am desparately trying to find a way to insert the data from a user form in multiple locations of a document. I can create the USerform and use VBA to insert the data at one bookmark but cannot insert the data in other parts of the document (without creating separately-named bookmarks) Any suggestions would be GREATLY appreciated. Thanks.

aalikhan@attbi.com
 
I just tried this out in Word 2000.

The key may be in how you reference the same bookmark field. I learned this from another post --

Every subsequent bookmark field of the same name should be inserted as --
* Insert -> Field...
* From the Categories list, click on Links and References.
* From the Field names list, click on Ref.
* In the field where Ref appears, insert your bookmark field name.

You may also have to check the Field codes check box within Tools -> Options -> View.
 
If that aint it, check your VBA code --

I generated the following by recording a macro for the find/replace function. Notice the Replace:=wdReplaceAll parm.

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "bmfield"
.Replacement.Text = txtTo
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
 
Here is the code I was using for the REF MERGEFIELD attempt. Any suggestions as to why it is not inserting the text in the second instance of the bookmark?

Private Sub cmdOK_Click()

Application.ScreenUpdating = False

With ActiveDocument
.Bookmarks("Recipient").Range.Text=
txtRecipient.Value
End With

Application.ScreenUpdating = True
Unload Me
End Sub

Thanks!
 
Try this
Create a property called Recipient in File|Properties and Custom tab.

Now whereever you need this value in the document put a field {DOCPROPERTY "Recipient"}.

Use the old Ctrl-A, F9 trick to refresh fields whenever you change the value of Recipient under File|Properties and hey presto!

I use this technique all the time. It works, it's simple and it saves time. Only problem is that most people using my templates type over the field instead of changing the property but I haven't found a solution to that.



 
plantj has a good idea with using DocProperty. A possible solution to his problem with users typing over the field is to embed the field code in a form field. That way the Ctrl-A-F9 will always revert the form field to its original value, that is, the value of the field code inside it. Users can type whatever they want into the form field, it will look differently, but a refresh will bring back your value. Of course if they deliberately edit the form field itself....you could always do continous section breaks, locking the forms etc. etc.

The following will insert a form field, with the DocProperty value, anywhere you want, as many times as you want.

Sub MakeFieldInForm()

' make a form field and insert a field code
'
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
With Selection.FormFields(1)
.Name = "Text1" ' or whatever you like
.Enabled = False
With .TextInput
' insert a field code into text value of form field
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.TypeText Text:="DocProperty""MyField"""
' MyField could be a string variable
' selected from a user form listing all
' of your custom docproperties
End With
End With
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top