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.Sav eAs Filename:=strFullDocPath
appword.activedocument.Sec tions(1).F ooters(1). Range.Sele ct
appword.Selection.Fields.U pdate
Anyone know why this might be happening?
Thanks in advance
C
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.Sav
appword.activedocument.Sec
appword.Selection.Fields.U
Anyone know why this might be happening?
Thanks in advance
C
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.
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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.
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.
ASKER
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.Sec tions(1).F ooters(1). Range.Sele ct
appword.Selection.Fields.U pdate
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
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.Sec
appword.Selection.Fields.U
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Are you all set now snave?
ASKER
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
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!
Maybe this will help:
http://support.microsoft.com/kb/240090
Please let me know.
Joanne