docvariable when empty gives error - how to stop error text in doc

J

justagrunt

Hi,
Using docvariables in a mail merge.
Using a record set to isolate the data from and access table.
Address1 = Nz(![Address1])
Address2 = Nz(![Address2])
Address3 = Nz(![Address3])
Address4 = Nz(![Address4])
Address5 = Nz(![Address5])
Address6 = Nz(![Address6])

then

Set docvar = WordDoc.Variables

docvar.Item("Address1").Value = Address1
docvar.Item("Address2").Value = Address2
docvar.Item("Address3").Value = Address3
docvar.Item("Address4").Value = Address4
docvar.Item("Address5").Value = Address5
docvar.Item("Address6").Value = Address6

problem lies if any of the fields has no information i get error - no
document variable supplied showing on the document.
Thought I'd cleared it with the Nz function.
How do I get a round the problem of a docvariable having the possibility of
no information as the feild in access has no information.
Say no information for address feilds 5 and 6.
 
D

Doug Robbins - Word MVP

The Access built-in Nz() function provides for two arguements.

Use Address1 = Nz(![Address1], " ")

so that Address1 will contain just a space if the corresponding field is
empty.

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

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