Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

DocVariable Problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
singeredel - 07 Mar 2005 15:13 GMT
I have a field code of DocVariable Quadis. Can anyone tell me why the
following code still displays an "Error! No document variable supplied" when
the variable QuadisNo$ is blank?

       If QuadisNo$ = "" Then
           ActiveDocument.Variables.Add Name:="Quadis", Value:=""
       Else: ActiveDocument.Variables.Add Name:="Quadis", Value:="DocID " +
QuadisNo$
       End If
       ActiveDocument.Fields.Update

I just need fields to display nothing if the variable is blank.

Thanks...
Signature

singeredel (Julie)

Jonathan West - 07 Mar 2005 15:43 GMT
>I have a field code of DocVariable Quadis. Can anyone tell me why the
> following code still displays an "Error! No document variable supplied"
[quoted text clipped - 10 lines]
>
> I just need fields to display nothing if the variable is blank.

Its the way Variables work - if they are blank, they are deleted altogether.
Put a single space in instead.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

Jay Freedman - 07 Mar 2005 15:57 GMT
Setting the value of any document variable to an empty string "" is exactly
the same as deleting it -- so even after your .Variables.Add statement, the
variable Quadis does not exist in the document. That's what the field result
is telling you.

You can insert a space character as the value of the variable, Value:=" ",
and the field will display a space. This should be ok unless something else
follows the field on the same line in the document.

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> I have a field code of DocVariable Quadis. Can anyone tell me why the
> following code still displays an "Error! No document variable
[quoted text clipped - 10 lines]
>
> Thanks...
Greg - 07 Mar 2005 16:01 GMT
Instead of setting your Variable Quadis to "" set it to " " then in
your Field code use

{ IF {DocVariable "Quadis" } = " """{DocVariable "Quadis"}}

I
Helmut Weber - 07 Mar 2005 16:03 GMT
Hi Julie,

working with fields isn't real programming from
my point of view, so I can help you only with
explaining what is going on:

MsgBox ActiveDocument.Variables.Count ' e.g. 5
ActiveDocument.Variables.Add Name:="Quadis", Value:=""
MsgBox ActiveDocument.Variables.Count ' still 5
so no variable was created.

Maybe microsoft.public.word.docmanagement
would be better suited for such a question.

Though there is sufficient knowledge here,
I guess, but unfortunately not by me.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Jean-Guy Marcil - 07 Mar 2005 16:12 GMT
singeredel was telling us:
singeredel nous racontait que :

> I have a field code of DocVariable Quadis. Can anyone tell me why the
> following code still displays an "Error! No document variable
[quoted text clipped - 8 lines]
>
> I just need fields to display nothing if the variable is blank.

Try:
'_______________________________________
Sub test()
Const VariableName As String = "Quadis"
Dim QuadisNo As String

QuadisNo = ""

ActiveDocument.Variables(VariableName).Value = "Temp"

If QuadisNo = "" Then
   ActiveDocument.Variables(VariableName).Value = ""
Else
   ActiveDocument.Variables(VariableName).Value = "DocID " & QuadisNo
End If
ActiveDocument.Fields.Update

End Sub
'_______________________________________

I think that if you use something like:
   ActiveDocument.Variables(VariableName).Value = ""
twice in a row (It could happen depending how often your code is run), then
the first time you set the variable to zero length and delete it, but the
fields seems to be able to handle that. If you do it a second time, then the
field displays the error message.

Another way around that is:
'_______________________________________
Sub test()
Const VariableName As String = "Quadis"
Dim QuadisNo As String

QuadisNo = ""

If QuadisNo = "" Then
   ActiveDocument.Variables(VariableName).Value = " "
Else
   ActiveDocument.Variables(VariableName).Value = "DocID " & QuadisNo
End If
ActiveDocument.Fields.Update

End Sub
'_______________________________________

But here you will get a space in lieu of the DOCVARIABLE field in the
document, and I don't know if this is acceptable in your case.

I am sure someone will be along shortly to explain the fine intricacies of
the DOCVARIABLE field!
.
Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.