Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-09-2017, 01:12 AM
cltay87 cltay87 is offline Text Form Field & REF Field Windows 7 32bit Text Form Field & REF Field Office 2010 32bit
Novice
Text Form Field & REF Field
 
Join Date: Feb 2017
Posts: 7
cltay87 is on a distinguished road
Default Text Form Field & REF Field

Hi all,



I'm facing difficulties for populating data from excel to word's text form field.

I've been using bookmarks in word in order to populate data from excel. However, due to the content that some data need to repeat in a document, I tried using Text Form Field and REF Field.

The problem came in when once I populated data to word, the text form field placeholder disappear which causes REF Field unable to track the data that was referred to, hence, the "Error! Reference source not found."

Is there anyway to retain the Text Field Form Placeholder after data is populated to word? So that I can generate duplicate data.

My excel and document as attached for your reference.

Appreciate for your help in advance!
Attached Files
File Type: zip Doc1.zip (23.3 KB, 9 views)
Reply With Quote
  #2  
Old 08-09-2017, 03:36 AM
Pecoflyer's Avatar
Pecoflyer Pecoflyer is offline Text Form Field & REF Field Windows 7 64bit Text Form Field & REF Field Office 2010 64bit
Expert
 
Join Date: Nov 2011
Location: Brussels Belgium
Posts: 2,779
Pecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant future
Default

Hi
is this question not intended for the MSWord forum?
__________________
Did you know you can thank someone who helped you? Click on the tiny scale in the right upper hand corner of your helper's post
Reply With Quote
  #3  
Old 08-09-2017, 03:51 AM
cltay87 cltay87 is offline Text Form Field & REF Field Windows 7 32bit Text Form Field & REF Field Office 2010 32bit
Novice
Text Form Field & REF Field
 
Join Date: Feb 2017
Posts: 7
cltay87 is on a distinguished road
Default

Should be at the right forum. Because I was asking for Excel VBA to solve my Text Form Field in Word. If there's solution for Word, it would be great.
Reply With Quote
  #4  
Old 08-09-2017, 04:28 AM
macropod's Avatar
macropod macropod is offline Text Form Field & REF Field Windows 7 64bit Text Form Field & REF Field Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Form fields only work in documents with 'filling in forms' protection applied. Unless your VBA code was changing the formfield's default property, anything you do to update the formfield would erase its contents. As it is, the error you're getting suggests that you're not writing to the formfield but are instead overwriting it and, hence, deleting its bookmark.

Instead of writing to formfields, you could just write the data to a bookmark (not just insert it at a bookmarked location), and cross-reference that bookmark. For code to update Word bookmarks correctly for that, see: https://www.msofficeforums.com/word-...html#post67058
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 08-09-2017, 07:20 PM
cltay87 cltay87 is offline Text Form Field & REF Field Windows 7 32bit Text Form Field & REF Field Office 2010 32bit
Novice
Text Form Field & REF Field
 
Join Date: Feb 2017
Posts: 7
cltay87 is on a distinguished road
Default

Hi Macropod, thanks for replying.

I tried adding your code into my existing code, like this :

Code:
Private Sub CommandButton1_Click()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Data Entry (B)")
Dim objWord As Object
Set objWord = CreateObject("Word.Application")
Dim BkMkRng As Range
objWord.Visible = True
objWord.Documents.Open "C:\Users\" & Environ("username") & "\Desktop\xxx\xxxN"
objWord.ActiveDocument.Unprotect Password:="xxx"
With objWord.ActiveDocument



.FormFields("pr1").Range.Text = ws.Range("C28").Value

 If .Bookmarks.Exists(StrBkMk) Then
    Set BkMkRng = .Bookmarks(StrBkMk).Range
    BkMkRng.Text = StrTxt
    .Bookmarks.Add StrBkMk, BkMkRng
    End If
  .Fields.Update


objWord.ActiveDocument.Protect Password:="xxx", NoReset:=False, Type:=wdAllowOnlyFormFields
End With

Set objWord = Nothing
End Sub
But fieldcode still disappear. Am I inserting the codes into wrong way?
Reply With Quote
  #6  
Old 08-09-2017, 07:27 PM
macropod's Avatar
macropod macropod is offline Text Form Field & REF Field Windows 7 64bit Text Form Field & REF Field Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

As I already said, there is no point using a formfield. what you should be using is a bookmark - which you update.

Furthermore, your code populates neither StrBkMk, BkMkRng, nor StrTxt and never defines either StrBkMk or StrTxt - even the definition of BkMkRng (as Range) is wrong in an automation context!
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Text Form Field & REF Field Macro to autofill a form field ONLY if the form field is blank upon entry Pindar Word VBA 2 01-12-2017 05:03 PM
Text Form Field & REF Field Insert text form field help sj80 Word 1 01-26-2016 10:50 PM
Text Form Field & REF Field Text form field in table tmarsh Word Tables 1 02-23-2015 07:43 AM
Text Form Field & REF Field Form field selection allows entry into form text box David C Word 1 10-24-2012 04:53 AM
Text Form Field & REF Field Form Fields - Create blank form text field with if statement? LAssist2011 Word 5 12-14-2011 03:02 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:42 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft