DOCVARIABLE not "updateable" (F9)
Author |
Message |
ralp #1 / 7
|
 DOCVARIABLE not "updateable" (F9)
I am automating Word thru a VB application. My Word Doc is full of DOCVARIABLE fields which I update using .Fields (idx).Result.Text = "Some new value". Nothing particularly remarkable. This works fine. I am able to insert text in Headers, Footers, and the Main Body. But when opening the created document later in Word I discovered that if I update the fields (F9), the values for the DOCVARIABLE fields in the Main Body - disappear! No error! The value is just gone. If I use F9 on fields in the Headers and Footers the values remain just as one would expect. What am I missing? (Should I post all the relevant code?) Thanks, -ralph
|
Sun, 30 Oct 2005 00:07:08 GMT |
|
 |
Dave Let #2 / 7
|
 DOCVARIABLE not "updateable" (F9)
Hi Ralph, First be sure that the document variables exist (I know, master of the obvious): MsgBox ActiveDocument.Variables("Test").Value If they exist and the fields "disappear", then turn on field codes so that we know that only the result of the field is an empty string and that the field hasn't truly disappeared. After that (and if you can't figure out what's happening), send a sample of the field that you're using and the code you use to write the Variables value. HTH
Quote: > I am automating Word thru a VB application. My Word Doc is > full of DOCVARIABLE fields which I update using .Fields > (idx).Result.Text = "Some new value". Nothing particularly > remarkable. > This works fine. I am able to insert text in Headers, > Footers, and the Main Body. But when opening the created > document later in Word I discovered that if I update the > fields (F9), the values for the DOCVARIABLE fields in the > Main Body - disappear! No error! The value is just gone. > If I use F9 on fields in the Headers and Footers the > values remain just as one would expect. > What am I missing? > (Should I post all the relevant code?) > Thanks, > -ralph
|
Sun, 30 Oct 2005 00:16:15 GMT |
|
 |
ralp #3 / 7
|
 DOCVARIABLE not "updateable" (F9)
After careful review (thanks to your comment about the obvious, I went and got another pair of eyes. <g>) I discovered that the "result" of an assignment to a DOCVARIABLE field ... { DOCVARIABLE "ConsumerName" \* MERGEFORMAT } in a header produced this... { DOCVARIABLE "ConsumerName" \* MERGEFORMAT }James R. Jones Note: the text is inserted outside the 'field' immediately after it. This was not what I expected. (I guess I am just a newbie after all. smile) Therefore the 'fields' in the header with the fields not showing - display the correct text, because the text is written to the document. The fields themselves display NO value. But the 'fields' themselves never did display any values. The 'fields' in the main body actually display the value. The reason the 'fields' in the header didn't looked affected is because after the (F9) the field display "nothing" but the text was still there. (Make sense? I hope so, because I am throughly confused at this point. <g> ) Apparently my method of "updating" fields is all wet. My code follows... With moWD For iSect = 1 To .Sections.Count ' Headers With .Sections(iSect).Headers (wdHeaderFooterPrimary).Range For idx = 1 To .Fields.Count If .Fields(idx).Type = wdFieldDocVariable Then sTmp = GetFieldVarName(.Fields(idx)) With .Fields(idx).Result Select Case sTmp Case "ConsumerName" .Text = mDetail.ConsumerName ... End Select End With End If Next idx End With For idx = 1 To .Fields.Count If .Fields(idx).Type = wdFieldDocVariable Then sTmp = GetFieldVarName(.Fields(idx)) With .Fields(idx).Result Select Case sTmp Case "ConsumerName" .Text = mDetail.ConsumerName ... End Select End With End If Next idx Next iSect .SaveAs FileName:=msSaveFileName, FileFormat:=wdFormatDocument, _ ReadOnlyRecommended:=True End With It seems like the going the "way of ranges" allows me to insert text using the 'field' as some kind of 'marker/bookmark', but DOES NOT assign a value? While using my method on the main body - DOES "assign the value", but the effect isn't permanent. Any suggestions? [It seemed like such a good idea at the time. <smile>] -ralph Quote: >-----Original Message----- >Hi Ralph, >First be sure that the document variables exist (I know, master of the >obvious): >MsgBox ActiveDocument.Variables("Test").Value >If they exist and the fields "disappear", then turn on field codes so that >we know that only the result of the field is an empty string and that the >field hasn't truly disappeared. After that (and if you can't figure out >what's happening), send a sample of the field that you're using and the code >you use to write the Variables value. >HTH
>> I am automating Word thru a VB application. My Word Doc is >> full of DOCVARIABLE fields which I update using .Fields >> (idx).Result.Text = "Some new value". Nothing particularly >> remarkable. >> This works fine. I am able to insert text in Headers, >> Footers, and the Main Body. But when opening the created >> document later in Word I discovered that if I update the >> fields (F9), the values for the DOCVARIABLE fields in the >> Main Body - disappear! No error! The value is just gone. >> If I use F9 on fields in the Headers and Footers the >> values remain just as one would expect. >> What am I missing? >> (Should I post all the relevant code?) >> Thanks, >> -ralph >.
|
Sun, 30 Oct 2005 02:04:12 GMT |
|
 |
Dave Let #4 / 7
|
 DOCVARIABLE not "updateable" (F9)
Hi Ralph, From what I can see, I think you might be handling this all wrong (sorry if I'm mistaken). You seem to be trying to set the .text value of a document variable field by changing the text of a specific field. This is not how document variable fields work at all. Try this in a blank document. Insert a field { DOCVARIABLE Test \* MERGEFORMAT } Select the field and press F9 (don't deselect the field though). The field result should be blank (i.e., you shouldn't see it). In VBA, run the following routine ActiveDocument.Variables.Add Name:="Test", Value:="myTest" Switch back to Word and press F9. Run the following routine: ActiveDocument.Fields(1).Result.text = "second test" Switch back to Word. It nows appears that you've updated your document variable, but that isn't so. Select the field and press F9. The more appropriate way to add and update document variables is something like the following: Dim oVar As Variable For Each oVar In ActiveDocument.Variables If oVar.Name = "Test" Then oVar.Value = "new value" Else ActiveDocument.Variables.Add Name:="Test", Value:="Start value" End If Next oVar HTH
Quote: > After careful review (thanks to your comment about the > obvious, I went and got another pair of eyes. <g>) I > discovered that the "result" of an assignment to a > DOCVARIABLE field ... > { DOCVARIABLE "ConsumerName" \* MERGEFORMAT } > in a header produced this... > { DOCVARIABLE "ConsumerName" \* MERGEFORMAT }James R. Jones > Note: the text is inserted outside the 'field' immediately > after it. This was not what I expected. (I guess I am just > a newbie after all. smile) > Therefore the 'fields' in the header with the fields not > showing - display the correct text, because the text is > written to the document. The fields themselves display NO > value. But the 'fields' themselves never did display any > values. > The 'fields' in the main body actually display the value. > The reason the 'fields' in the header didn't looked > affected is because after the (F9) the field > display "nothing" but the text was still there. (Make > sense? I hope so, because I am throughly confused at this > point. <g> ) > Apparently my method of "updating" fields is all wet. My > code follows... > With moWD > For iSect = 1 To .Sections.Count > ' Headers > With .Sections(iSect).Headers > (wdHeaderFooterPrimary).Range > For idx = 1 To .Fields.Count > If .Fields(idx).Type = wdFieldDocVariable Then > sTmp = GetFieldVarName(.Fields(idx)) > With .Fields(idx).Result > Select Case sTmp > Case "ConsumerName" > .Text = mDetail.ConsumerName > ... > End Select > End With > End If > Next idx > End With > For idx = 1 To .Fields.Count > If .Fields(idx).Type = wdFieldDocVariable Then > sTmp = GetFieldVarName(.Fields(idx)) > With .Fields(idx).Result > Select Case sTmp > Case "ConsumerName" > .Text = mDetail.ConsumerName > ... > End Select > End With > End If > Next idx > Next iSect > .SaveAs FileName:=msSaveFileName, > FileFormat:=wdFormatDocument, _ > ReadOnlyRecommended:=True > End With > It seems like the going the "way of ranges" allows me to > insert text using the 'field' as some kind > of 'marker/bookmark', but DOES NOT assign a value? While > using my method on the main body - DOES "assign the > value", but the effect isn't permanent. > Any suggestions? > [It seemed like such a good idea at the time. <smile>] > -ralph > >-----Original Message----- > >Hi Ralph, > >First be sure that the document variables exist (I know, > master of the > >obvious): > >MsgBox ActiveDocument.Variables("Test").Value > >If they exist and the fields "disappear", then turn on > field codes so that > >we know that only the result of the field is an empty > string and that the > >field hasn't truly disappeared. After that (and if you > can't figure out > >what's happening), send a sample of the field that you're > using and the code > >you use to write the Variables value. > >HTH
> >> I am automating Word thru a VB application. My Word Doc > is > >> full of DOCVARIABLE fields which I update using .Fields > >> (idx).Result.Text = "Some new value". Nothing > particularly > >> remarkable. > >> This works fine. I am able to insert text in Headers, > >> Footers, and the Main Body. But when opening the created > >> document later in Word I discovered that if I update the > >> fields (F9), the values for the DOCVARIABLE fields in > the > >> Main Body - disappear! No error! The value is just gone. > >> If I use F9 on fields in the Headers and Footers the > >> values remain just as one would expect. > >> What am I missing? > >> (Should I post all the relevant code?) > >> Thanks, > >> -ralph > >.
|
Sun, 30 Oct 2005 02:33:39 GMT |
|
 |
Charles Kenyo #5 / 7
|
 DOCVARIABLE not "updateable" (F9)
Note that DocVariable fields in headers will crash Word 97! -- Charles Kenyon Word New User FAQ & Web Directory: <URL: http://www.addbalance.com/word/index.htm> Intermediate User's Guide to Microsoft Word (supplemented version of Microsoft's Legal Users' Guide) <URL: http://www.addbalance.com/usersguide/index.htm> Word Resources Page <URL: http://www.addbalance.com/word/wordwebresources.htm> See also the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome! --------- --------- --------- --------- --------- --------- This message is posted to a newsgroup. Please post replies and questions to the newsgroup so that others can learn from my ignorance and your wisdom.
Quote: > I am automating Word thru a VB application. My Word Doc is > full of DOCVARIABLE fields which I update using .Fields > (idx).Result.Text = "Some new value". Nothing particularly > remarkable. > This works fine. I am able to insert text in Headers, > Footers, and the Main Body. But when opening the created > document later in Word I discovered that if I update the > fields (F9), the values for the DOCVARIABLE fields in the > Main Body - disappear! No error! The value is just gone. > If I use F9 on fields in the Headers and Footers the > values remain just as one would expect. > What am I missing? > (Should I post all the relevant code?) > Thanks, > -ralph
|
Sun, 30 Oct 2005 07:14:14 GMT |
|
 |
ralp #6 / 7
|
 DOCVARIABLE not "updateable" (F9)
Thanks Dave for your reply. And thanks Charles for the warning. I changed my method to using that which Dave suggested, but now I get either the same problem (F9 clears the field and the value is lost) or I get sporadic problems with a particular docvariable not found, and/or when even added not showing up in the saved file. Agggghhhhhhh! I have been reduced to a small child rolled up in a fetal postion under my desk, clutching my Word Object Library printout, muttering "I thought I could do this, I thought I could do this, ...". All I wanted to do was open a selected template, fill some fields with data, and save the document out to be later massaged by someone else, and do it from VB using automation. This was to be a few hours addin feature to an existing project. I told my boss - No problem. It has been a week now... (Sorry I am starting to ramble.) So far I have played with selections, bookmarks, ranges, docvariables, macros, cut 'n paste (clipboard), ... The horror has been that just about everything "works" to some degree or another - but breaks down somewhere else. Can complete madness be far behind? Gentlemen, in your opinion how does one go about doing this? I don't need complete code, just a pointer to a "best practices". Should I abandon using docvariables? Should I just use a plain text ("<<place address here>>") replacement technique? Should I go back to defining ranges with bookmarks? What? Thanks, -ralph Quote: >-----Original Message----- >Hi Ralph, >From what I can see, I think you might be handling this all wrong (sorry if >I'm mistaken). You seem to be trying to set the .text value of a document >variable field by changing the text of a specific field. This is not how >document variable fields work at all. Try this in a blank document. Insert a >field >{ DOCVARIABLE Test \* MERGEFORMAT } >Select the field and press F9 (don't deselect the field though). The field >result should be blank (i.e., you shouldn't see it). In VBA, run the >following routine >ActiveDocument.Variables.Add Name:="Test", Value:="myTest" >Switch back to Word and press F9. Run the following routine: >ActiveDocument.Fields(1).Result.text = "second test" >Switch back to Word. It nows appears that you've updated your document >variable, but that isn't so. Select the field and press F9. The more >appropriate way to add and update document variables is something like the >following: >Dim oVar As Variable >For Each oVar In ActiveDocument.Variables > If oVar.Name = "Test" Then > oVar.Value = "new value" > Else > ActiveDocument.Variables.Add Name:="Test",
Value:="Start value" Quote: > End If >Next oVar >HTH
>> After careful review (thanks to your comment about the >> obvious, I went and got another pair of eyes. <g>) I >> discovered that the "result" of an assignment to a >> DOCVARIABLE field ... >> { DOCVARIABLE "ConsumerName" \* MERGEFORMAT } >> in a header produced this... >> { DOCVARIABLE "ConsumerName" \* MERGEFORMAT }James R. Jones >> Note: the text is inserted outside the 'field' immediately >> after it. This was not what I expected. (I guess I am just >> a newbie after all. smile) >> Therefore the 'fields' in the header with the fields not >> showing - display the correct text, because the text is >> written to the document. The fields themselves display NO >> value. But the 'fields' themselves never did display any >> values. >> The 'fields' in the main body actually display the value. >> The reason the 'fields' in the header didn't looked >> affected is because after the (F9) the field >> display "nothing" but the text was still there. (Make >> sense? I hope so, because I am throughly confused at this >> point. <g> ) >> Apparently my method of "updating" fields is all wet. My >> code follows... >> With moWD >> For iSect = 1 To .Sections.Count >> ' Headers >> With .Sections(iSect).Headers >> (wdHeaderFooterPrimary).Range >> For idx = 1 To .Fields.Count >> If .Fields(idx).Type = wdFieldDocVariable Then >> sTmp = GetFieldVarName(.Fields(idx)) >> With .Fields(idx).Result >> Select Case sTmp >> Case "ConsumerName" >> .Text = mDetail.ConsumerName >> ... >> End Select >> End With >> End If >> Next idx >> End With >> For idx = 1 To .Fields.Count >> If .Fields(idx).Type = wdFieldDocVariable Then >> sTmp = GetFieldVarName(.Fields(idx)) >> With .Fields(idx).Result >> Select Case sTmp >> Case "ConsumerName" >> .Text = mDetail.ConsumerName >> ... >> End Select >> End With >> End If >> Next idx >> Next iSect >> .SaveAs FileName:=msSaveFileName, >> FileFormat:=wdFormatDocument, _ >> ReadOnlyRecommended:=True >> End With >> It seems like the going the "way of ranges" allows me to >> insert text using the 'field' as some kind >> of 'marker/bookmark', but DOES NOT assign a value? While >> using my method on the main body - DOES "assign the >> value", but the effect isn't permanent. >> Any suggestions? >> [It seemed like such a good idea at the time. <smile>] >> -ralph >> >-----Original Message----- >> >Hi Ralph, >> >First be sure that the document variables exist (I know, >> master of the >> >obvious): >> >MsgBox ActiveDocument.Variables("Test").Value >> >If they exist and the fields "disappear", then turn on >> field codes so that >> >we know that only the result of the field is an empty >> string and that the >> >field hasn't truly disappeared. After that (and if you >> can't figure out >> >what's happening), send a sample of the field that you're >> using and the code >> >you use to write the Variables value. >> >HTH
>> >> I am automating Word thru a VB application. My Word Doc >> is >> >> full of DOCVARIABLE fields which I update using .Fields >> >> (idx).Result.Text = "Some new value". Nothing >> particularly >> >> remarkable. >> >> This works fine. I am able to insert text in Headers, >> >> Footers, and the Main Body. But when opening the created >> >> document later in Word I discovered that if I update the >> >> fields (F9), the values for the DOCVARIABLE fields in >> the >> >> Main Body - disappear! No error! The value is just gone. >> >> If I use F9 on fields in the Headers and Footers the >> >> values remain just as one would expect. >> >> What am I missing? >> >> (Should I post all the relevant code?) >> >> Thanks, >> >> -ralph >> >. >.
|
Sun, 30 Oct 2005 22:52:09 GMT |
|
 |
Steve Lan #7 / 7
|
 DOCVARIABLE not "updateable" (F9)
Hi Ralph, Nice of you to join the rest of us under the desk. Word does that eventually to us all, I think! :^) If the information you are placing in the document is not changing after creation, IMHO the bookmarks method of insertion conjoined with saving additional non-printing information about the document in document variables (docvars) works the best. In my specific case, we create and modify approximately 5000-10,000 documents annually for the Nevada State Legislature (Bill Drafts,Bills, Amendments, etc) using this method with an essential screwup rate of zero for creating the documents. Modification screwup rates are higher, since the user can (and does) kill the bookmarks occasionally. I have code to ensure document integrity (e.g., bookmarks exist and in the right places) on the BeforeClose Event. Still, even with that, I can't completely save these folks from themselves. There is the occasional manual intervention necessary to set a bookmark (or docvar) correctly. I can specifically recall 4 such times since our session started; approximately 4500 documents ago though there may have been more. Again, just my opinion. HTH and see you under the desk again sometime! Steve
Quote: > Thanks Dave for your reply. > And thanks Charles for the warning. > I changed my method to using that which Dave suggested, > but now I get either the same problem (F9 clears the field > and the value is lost) or I get sporadic problems with a > particular docvariable not found, and/or when even added > not showing up in the saved file. > Agggghhhhhhh! > I have been reduced to a small child rolled up in a fetal > postion under my desk, clutching my Word Object Library > printout, muttering "I thought I could do this, I thought > I could do this, ...". > All I wanted to do was open a selected template, fill some > fields with data, and save the document out to be later > massaged by someone else, and do it from VB using > automation. This was to be a few hours addin feature to an > existing project. I told my boss - No problem. It has been > a week now... (Sorry I am starting to ramble.) > So far I have played with selections, bookmarks, ranges, > docvariables, macros, cut 'n paste (clipboard), ... The > horror has been that just about everything "works" to some > degree or another - but breaks down somewhere else. Can > complete madness be far behind? > Gentlemen, in your opinion how does one go about doing > this? I don't need complete code, just a pointer to > a "best practices". Should I abandon using docvariables? > Should I just use a plain text ("<<place address here>>") > replacement technique? Should I go back to defining ranges > with bookmarks? What? > Thanks, > -ralph > >-----Original Message----- > >Hi Ralph, > >From what I can see, I think you might be handling this > all wrong (sorry if > >I'm mistaken). You seem to be trying to set the .text > value of a document > >variable field by changing the text of a specific field. > This is not how > >document variable fields work at all. Try this in a blank > document. Insert a > >field > >{ DOCVARIABLE Test \* MERGEFORMAT } > >Select the field and press F9 (don't deselect the field > though). The field > >result should be blank (i.e., you shouldn't see it). In > VBA, run the > >following routine > >ActiveDocument.Variables.Add Name:="Test", Value:="myTest" > >Switch back to Word and press F9. Run the following > routine: > >ActiveDocument.Fields(1).Result.text = "second test" > >Switch back to Word. It nows appears that you've updated > your document > >variable, but that isn't so. Select the field and press > F9. The more > >appropriate way to add and update document variables is > something like the > >following: > >Dim oVar As Variable > >For Each oVar In ActiveDocument.Variables > > If oVar.Name = "Test" Then > > oVar.Value = "new value" > > Else > > ActiveDocument.Variables.Add Name:="Test", > Value:="Start value" > > End If > >Next oVar > >HTH
> >> After careful review (thanks to your comment about the > >> obvious, I went and got another pair of eyes. <g>) I > >> discovered that the "result" of an assignment to a > >> DOCVARIABLE field ... > >> { DOCVARIABLE "ConsumerName" \* MERGEFORMAT } > >> in a header produced this... > >> { DOCVARIABLE "ConsumerName" \* MERGEFORMAT }James R. > Jones > >> Note: the text is inserted outside the 'field' > immediately > >> after it. This was not what I expected. (I guess I am > just > >> a newbie after all. smile) > >> Therefore the 'fields' in the header with the fields not > >> showing - display the correct text, because the text is > >> written to the document. The fields themselves display > NO > >> value. But the 'fields' themselves never did display any > >> values. > >> The 'fields' in the main body actually display the > value. > >> The reason the 'fields' in the header didn't looked > >> affected is because after the (F9) the field > >> display "nothing" but the text was still there. (Make > >> sense? I hope so, because I am throughly confused at > this > >> point. <g> ) > >> Apparently my method of "updating" fields is all wet. My > >> code follows... > >> With moWD > >> For iSect = 1 To .Sections.Count > >> ' Headers > >> With .Sections(iSect).Headers > >> (wdHeaderFooterPrimary).Range > >> For idx = 1 To .Fields.Count > >> If .Fields(idx).Type = wdFieldDocVariable > Then > >> sTmp = GetFieldVarName(.Fields(idx)) > >> With .Fields(idx).Result > >> Select Case sTmp > >> Case "ConsumerName" > >> .Text = mDetail.ConsumerName > >> ... > >> End Select > >> End With > >> End If > >> Next idx > >> End With > >> For idx = 1 To .Fields.Count > >> If .Fields(idx).Type = wdFieldDocVariable Then > >> sTmp = GetFieldVarName(.Fields(idx)) > >> With .Fields(idx).Result > >> Select Case sTmp > >> Case "ConsumerName" > >> .Text = mDetail.ConsumerName > >> ... > >> End Select > >> End With > >> End If > >> Next idx > >> Next iSect > >> .SaveAs FileName:=msSaveFileName, > >> FileFormat:=wdFormatDocument, _ > >> ReadOnlyRecommended:=True > >> End With > >> It seems like the going the "way of ranges" allows me to > >> insert text using the 'field' as some kind > >> of 'marker/bookmark', but DOES NOT assign a value? While > >> using my method on the main body - DOES "assign the > >> value", but the effect isn't permanent. > >> Any suggestions? > >> [It seemed like such a good idea at the time. <smile>] > >> -ralph > >> >-----Original Message----- > >> >Hi Ralph, > >> >First be sure that the document variables exist (I > know, > >> master of the > >> >obvious): > >> >MsgBox ActiveDocument.Variables("Test").Value > >> >If they exist and the fields "disappear", then turn on > >> field codes so that > >> >we know that only the result of the field is an empty > >> string and that the > >> >field hasn't truly disappeared. After that (and if you > >> can't figure out > >> >what's happening), send a sample of the field that > you're > >> using and the code > >> >you use to write the Variables value. > >> >HTH
> >> >> I am automating Word thru a VB application. My Word > Doc > >> is > >> >> full of DOCVARIABLE fields which I update > using .Fields > >> >> (idx).Result.Text = "Some new value". Nothing > >> particularly > >> >> remarkable. > >> >> This works fine. I am able to insert text in Headers, > >> >> Footers, and the Main Body. But when opening the > created > >> >> document later in Word I discovered that if I update > the > >> >> fields (F9), the values for the DOCVARIABLE fields in > >> the > >> >> Main Body - disappear! No error! The value is just > gone. > >> >> If I use F9 on fields in the Headers and Footers the > >> >> values remain just as one would expect. > >> >> What am I missing? > >> >> (Should I post all the relevant code?) > >> >> Thanks, > >> >> -ralph > >> >. > >.
|
Sun, 30 Oct 2005 23:17:41 GMT |
|
|
1. "must use updateable query" Question
2. *"*-.,._,.-*"* I"LL TRADE VISUAL C++ FOR VBASIC *"*-.,_,.-*"*
3. : VB6 Problem: "The memory could not be "read"/"written""
4. VB6 Problem: "The memory could not be "read"/"written""
5. GetObject("","InternetExplorer.Application") fails in Excel VBA
6. SysCmd 603, "path","path"
7. Disabling "BACK"/"FORWARD" buttons
8. Loop print "VARIABLE", "VARIABLE"
9. DLL or something like "#"#ยค#"!"#
10. Disabling "BACK"/"FORWARD" buttons
11. CreateObject("Excel","//server"), MsgBox output
12. Problem With "window.showmodaldialog("")"
|
|
|