Using DocVariables

P

PRegis08

I keep getting the "Error! No document variable supplied!" error when
information from my userform is left blank. Is there any way that I can get
around that?


Thank you in advance!


Patrick
 
G

Greg

Yes I am sure there is. Determining what that way is would be a lot easier
if you would have provided some details.

A shot in the dark:

A Variable can't be nothing (the technical term might be zero lenght string,
but I am not sure), so if your userform fields is blank then set the variable
value = " "
 
P

PRegis08

I apologize for my vagueness. I have a userform that gets customer
demographic information so that it can be applied to the letter template. I
am using the DocVariables to display the inputed information. If any
information is left blank (i.e. the individual does not have a middle
initial) it will display that error message instead. I didn't know if there
was a way to tell it if that particular variable was left blank that it
wouldn't need that particular docVariable.

Thank you so much.


Patrick
 
G

Greg

I suspect that your problem is that you are trying to assign a zero length
string to the the variable value.

For example if you have a docvariable field named "Test"

{DocVariable "Test"}

And populate it like this:

ActiveDocument.Variables("Test").Value = "Testing"
ActiveDocument.Fields.Update
MsgBox ActiveDocument.Variables.Count

All will be well.

Then if you run:

ActiveDocument.Variables("Test").Value = ""
ActiveDocument.Fields.Update
MsgBox ActiveDocument.Variables.Count

You will see that assigning a zero length string kills the variable.

Try something like this:


Private Sub CommandButton1_Click()
Dim oVars As Variables
Set oVars = ActiveDocument.Variables
If Len(Me.TextBox1.Text) > 0 Then
oVars("CustInitials").Value = Me.TextBox1.Text
Else
oVars("CustInitials").Value = " "
End If
ActiveDocument.Fields.Update
Me.Hide

End Sub
 
D

Doug Robbins - Word MVP on news.microsoft.com

You can use the following field construction in the document

{ IF { DOCVARIABLE varName } = "Error! No document variable supplied." ""
{ DOCVARIABLE varName } }

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