?
Solved

Update Doc Property field in text box using automation

Posted on 2005-03-03
12
Medium Priority
?
1,514 Views
Last Modified: 2012-06-27
I have a word template that is used to create a new document from within an Access database.  When the Access VBA routine is run, data from Database is used to update the document properties of a new word document based on my template.  This works fine and the document is created correctly, properties are filled with daa and bookmarks are filled with text as appropriate.

The document template has a number of fields in the header including three text boxes.  These update fine and display the correct information.

The main body of the document has two text boxes with fields in them but these do not get updated along with everything else.  The information is in the custom document property but currently these fields have to be updated manually.

The code usedto update the fields within the document is as follows... (appword is my word document object)

With appword
        .Visible = True
        .Activate
        .Selection.WholeStory
        .Selection.Fields.Update
End With
   
appword.activedocument.SaveAs Filename:=strFullDocPath
appword.activedocument.Sections(1).Footers(1).Range.Select
appword.Selection.Fields.Update

Anyone know why this might be happening?

Thanks in advance

C
0
Comment
Question by:snavebelac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
12 Comments
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 13451349
Can you please explain why you would use text boxes in the body of a document?   And what type of fields are you using?  That's very important to know as well as the version of Word you're running.

Maybe this will help:
http://support.microsoft.com/kb/240090

Please let me know.  

Joanne
0
 
LVL 21

Expert Comment

by:Eric Fletcher
ID: 13451734
The file needs to be saved before the field will display the file name and path. It will show up in a header because by the time you see it, the header will have been refreshed automatically during Word's pagination. Try saving it first, then update the fields and save it a second time.
0
 
LVL 6

Author Comment

by:snavebelac
ID: 13451813
JOrzech

Version: Word 2003
Fields types.  They are custom docvument properties.  All strings (i dont think there any other types)

I am using text boxes to get two distinct pieces of information in two columns.  I do not want the infomration form the first column spilling into the second column and I the length of the text could vary considerably so I put the field codes in text boxes and positioned them next to each other.  I have done exaclty the same in the header and it seems to work perfectly !!

If there is a better way to acieve the same layout I would glady implement it.

EricFletcher

The filename and path are showing up in the footer just fine.  There is another save which I did not include in my source which does exactly what you have described.  The fields which do not getupdated are Custom document properties.

Thank you both for your input

C
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 37

Accepted Solution

by:
Joanne M. Orzech earned 1000 total points
ID: 13451942
snavebelac:

Why don't you just put the codes into a table rather than text boxes and all problems should be resolved.  

If you need further assistance, please post.

Joanne
0
 
LVL 6

Author Comment

by:snavebelac
ID: 13452100
Thanks JOrzech - I cannot believe I had not thought of that !!!  I feel like a complete idiot !!

Anyway, mental block aside - do you know of anyway of fixing what i actually have.  Just in case it becomes necessary in the future.

Thanks again for your help

C

0
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 13452287
Oh my goodness snave - not to worry.  We all have those "moments" - although mine now fall in the category of "senior moments" *sobbing and laughing at the same time*


I would just select the text you have in one text box, press Control C to copy it (assuming it's more than a couple lines), then delete the text box and paste it where you want it to appear.  If its a lot of text, you could select the text, go to Table, Convert Text to Table, and then create a one column table.  Then select the table, and split the columns into two.  In the checkbox where it says to merge cells (or something like that) before splitting, uncheck it.

Do the same with the second text box and format as desired.  Past that into the second column of the table you created above.  If you need more help, please let me know.  I had some medical tests done this morning and am feeling REALLY GOOD due to the anesthetic - so catch me while I'm up.  I'll probably be crashing within a few hours!  

So far, I've only been addressing the issue of the text boxes but if you need help with filename/path info - I've got a lot of experience with that as well - as I know Eric does from the wonderful information he posts.
0
 
LVL 6

Author Comment

by:snavebelac
ID: 13453589
There is something else you might be able to help me with -.  you certainly deserve the 500 points for pointing out the blatantly obvious but perhaps you wont mind answering this as well..

When the fields are updated via code I use the following line to update the footer to reflect the file path after a save.

appword.activedocument.Sections(1).Footers(1).Range.Select
appword.Selection.Fields.Update

When this section executes the word document view changes to Normal view with the footer expanded in a separate window/section at the bottom of the page.  Is there any way to either prevent this from happening or change the view back to print layout view via code.

Thanks again for you help - it is very much appreciated..

C
0
 
LVL 21

Assisted Solution

by:Eric Fletcher
Eric Fletcher earned 1000 total points
ID: 13454382
Try something like this:
ActiveDocument.ActiveWindow.View.Type = wdPrintView






0
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 13460511
Are you all set now snave?
0
 
LVL 6

Author Comment

by:snavebelac
ID: 13460779
Everything is working and looking sweeet.  Thanks you both very much indeed.

MS Access I can do - MS Word is a strange and elusive beast for me, never quite predictable...!!

C

0
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 13460797
Terrific!  Thanks for the points and grade snave.
0
 
LVL 21

Expert Comment

by:Eric Fletcher
ID: 13461124
Thanks snave... I'm just the opposite: Access looks like it would be really useful for some things I do but it remains elusive to me!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question