Error! No document variable supplied.

C

Carlos Paulino

Hi to all
I have developed a system in Delphi and want to print into Word some
information. I have created the field in Delphi that will print in word
(DOCVARIABLE varname, IF{DOCVARIABLE varname}=" " "" ) but I keep having the
message "Error! No document variable supplied." when no data is in Delphi
database field. It works when there is data. Can any one out there help me in
building the intructions to avoid the message mentioned above when the field
is blank?

Thanks for your valuable help.
 
J

Jean-Guy Marcil

Carlos Paulino said:
Hi to all
I have developed a system in Delphi and want to print into Word some
information. I have created the field in Delphi that will print in word
(DOCVARIABLE varname, IF{DOCVARIABLE varname}=" " "" ) but I keep having the
message "Error! No document variable supplied." when no data is in Delphi
database field. It works when there is data. Can any one out there help me in
building the intructions to avoid the message mentioned above when the field
is blank?

If you create a DOCVARIABLE and then set it to "", you are actually deleting
it. So any further reference to that DOCVARIABLE will generate an error
message.
 
C

Carlos Paulino

Jean-Guy:
What then could the right instructions not to get the error message. Will
appreciate your help on this issue.
 
D

Doug Robbins - Word MVP

If there is not data, set the .Value of the variable to " "

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

Jean-Guy Marcil

Carlos Paulino said:
Jean-Guy:
What then could the right instructions not to get the error message. Will
appreciate your help on this issue.

You have to cycle through the Document Variable collection, if the one you
are looking far is not there, you have to create it.

For example, in VBA:

Dim i As Long
Dim varname As String
Dim boolCreateVar As Boolean

varname = "MyVariable"
boolCreateVar = True

If ActiveDocument.Variables.Count > 0 Then
For i = 1 To ActiveDocument.Variables.Count
If ActiveDocument.Variables(i).Name = varname Then
boolCreateVar = False
Exit For
End If
Next
End If

If boolCreateVar Then
ActiveDocument.Variables.Add varname, "SomeValue"
End If

'Do what you have to do with that variable here


But, as Doug suggested, it is by far easier to make sure that variables
always have at least a space as a value, then you know they always exist.
This is easily done since variables can only be created/modified via code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top