Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Update Doc Property field in text box using automation

Posted on 2005-03-03
12
Medium Priority
?
1,518 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
  • 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
[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

 
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

If you work with Word a lot, you probably use styles. If you use styles a lot, you've probably balled your fist more often than not when working with the ribbon. In Word 2007/2010, one of the things that I find missing when using styles is a quic…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
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

581 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