error no document variable message

A

Associates

Hi,

I've got the error message that says "Error! No document variable supplied"
coming from DOCVARIABLE.

I have checked many times to ensure that the docvariable can be either some
value or nothing but to no avail.

Here is the code i have in the userform
If Me.txtRecipientTitle.Value <> "" Then
MsgBox "value"
With ActiveDocument
.Variables("title").Value = txtRecipientTitle.Text
.Fields.Update
.PrintPreview
.ClosePrintPreview
End With
Else
MsgBox "no value"
With ActiveDocument
.Variables("title").Value = ""
.Fields.Update
.PrintPreview
.ClosePrintPreview
End With
End If

When i deliberately left the textbox "txtRecipientTitle" empty, it printed
"no value". That's good. Then, when i did printpreview, i got the above error
message. I don't understand where i did wrong.

Any helps are greatly appreciated.

Thank you in advance
 
D

Doug Robbins - Word MVP

With

.Variables("title").Value = ""

you are setting the variable to a Null string which is why you are getting
the error message.

Replace that with

.Variables("title").Value = " "

and the field will display a single space and you will avoid the message.


--
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
 
A

Associates

Hi Doug,

Of course, i could put a single space inside "". Well done, Doug. I just
could not think of that.

Thank you once again
 

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