Link to home
Start Free TrialLog in
Avatar of snavebelac
snavebelac

asked on

Update Doc Property field in text box using automation

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
Avatar of Joanne M. Orzech
Joanne M. Orzech
Flag of United States of America image

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
Avatar of Eric Fletcher
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.
Avatar of snavebelac
snavebelac

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Joanne M. Orzech
Joanne M. Orzech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

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.
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Are you all set now snave?
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

Terrific!  Thanks for the points and grade snave.
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!