New document displays "Error! No document variable supplied."

D

dickens1228

I've created a template with several user forms and numerous docvariable
fields in the document corresponding to text boxes on the user forms. When I
create a new document based on this template, the "Error! No document
variable supplied." message appears as soon as the document is created
(before any data is entered into the user forms). How do I prevent this
error message from appearing in every Docvariable field in the document
before the user forms are completed?
 
D

Doug Robbins - Word MVP on news.microsoft.com

Open the template and run a macro containing the following code and then
save and close the template

Dim i As Long
With ActiveDocument
For i = 1 To .Variables.Count
.Variables(i).Value = " "
Next i
End With



--
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, originally posted via msnews.microsoft.com
 
D

dickens1228

Unfortunately, your suggestion didn't work.

When I place my cursor over the "i" in the macro, it says "i = 4" which I
think means it is not counting my DOCVARIABLE fields (I think it's only
counting the USERNAME, USERADDRESS, USERINITIALS and CREATEDATE fields
because they are the only other fields in the document besides the
DOCVARIABLE fields). Additionally, when I place the cursor over
".Variables.Count" in the macro, it says, ".Variables.Count = <Object
variable or With block variable not set>".

I'm using Word 2007 and saving the template as a Word 97-2003 template. The
weird thing is that I created an abbreviated "test" version of the template
using the same methodology, and the "Error! No document variable supplied"
message DOES NOT appear when I create a new document based on the test
template, and I can't see any difference in the way the two documents are
coded.

I'm really new at this, so I'm sure I'm doing something really stupid. The
template works beautifully, though, as long as the text boxes are not left
empty.

Any additional assistance you can provide will be greatly appreciated.
 
D

Doug Robbins - Word MVP on news.microsoft.com

I certainly works here.

It will not act upon the USERNAME, USERADDRESS, USERINITIALS and CREATEDATE
fields or any other fields in the document as they are not variables. What
the code does is set the value for each variable in the document and it you
then update the fields in the document, the docvariable fields will show
that value.

You could add .Range.Fields.Update before the End With so that the code also
does the updating for you

Dim i As Long
With ActiveDocument
For i = 1 To .Variables.Count
.Variables(i).Value = " "
Next i
.Range.Fields.Update
End With


--
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, originally posted via msnews.microsoft.com
 

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