DOCUMENT VARIABLES

J

JJ

OS - XP Prof SP2, Office 2003.
I have a VBA Userform with a text box where people type in the number
of parties to the
agreement. If they type "2" then it must prompt twice for the 1st
Party name and 1st Party ID or Registration Number and prompt again
for 2nd Party and 2nd Party ID or Registration Number. If they type
"3" then it must prompt three times and assign to all different
variables. Then I have a word template which I would like to program
saying {DOCVARIABLE 1stParty} to insert the 1st party name, then
{DOCVARIABLE 1stPartyRegNo} the word "and" {DOCVARIABLE 2ndParty} to
insert the 2nd party name, then {DOCVARIABLE 2ndPartyRegNo}. However
if you have 3 parties it must do {DOCVARIABLE 1stPartyRegNo} to hard
returns (blank spaces) {DOCVARIABLE 2ndParty} to insert the 2nd party
name, then {DOCVARIABLE 2ndPartyRegNo} then the word "and" and
{DOCVARIABLE 3rdParty} {DOCVARIABLE 3rdPartyRegNo}. I know how to do
the form but I have no clue as to how to program the document for it
to know when to use 2 parties or when to use 3 parties. I thought of
something like "if docvariable parties = 2 then docvariable 1st
Party,
docvariable 2nd party and docvariable 3rd party" but somehow I am not
managing to get the programming in the word template to understand my
commands. Unless I assign the whole toot to one variable and only
insert the one variable in my document. Any assistance or ideas will
be appreciated.
 
D

Doug Robbins - Word MVP

Assuming that you have a control named txtParties, then use the following
code

With ActiveDocument
.Variables("FirstParty").Value = txtFirstParty
.Variables("FirstPartyID").Value = txtFirstPartyID
.Variables("SecondParty").Value = txtSecondParty
.Variables("SecondPartyID").Value = txtSecondPartyID
If txtParties = 3 then
.Variables("ThirdParty").Value = vbCr & "and" & vbCr & txtThirdParty
.Variables("FirstPartyID").Value = txtThirdPartyID
End If
.Range.Fields.Update
End With
 
J

JJ

Assuming that you have a control named txtParties, then use the following
code

With ActiveDocument
.Variables("FirstParty").Value = txtFirstParty
.Variables("FirstPartyID").Value = txtFirstPartyID
.Variables("SecondParty").Value = txtSecondParty
.Variables("SecondPartyID").Value = txtSecondPartyID
If txtParties = 3 then
.Variables("ThirdParty").Value = vbCr & "and" & vbCr & txtThirdParty
.Variables("FirstPartyID").Value = txtThirdPartyID
End If
.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






- Show quoted text -

Doug thanx that's perfect but I already had that. The problem is how
do I stop having Errors in my word document as in the word document I
say {DOCVARIABLE Firstparty] {DOCVARIABLE SecondParty} which works
correct as those variables always exist. Then I have {DOCVARIABLE
Thirdparty} but if there are isn't a third party the DOCVARIABLES
gives an error in my document and it stays there. Therefore me asking
how do I programme the document to say if the variable exist place it
in the specific place in the document. If it doesn't exist, ignore it.
So if Docvariable thirdparty is "" ignore it. I hope you understand
what I am trying to say.
 
D

Doug Robbins - Word MVP

Before I posted that, I did a bit of research and came to the conclusion
that if you do not assign a value to the variable (which is not being done
because in the case of the ThirdParty variables, they are inside the
If...End If construction.

The alternative would be to create the whole shootin match as one variable.

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

JJ said:
Assuming that you have a control named txtParties, then use the following
code

With ActiveDocument
.Variables("FirstParty").Value = txtFirstParty
.Variables("FirstPartyID").Value = txtFirstPartyID
.Variables("SecondParty").Value = txtSecondParty
.Variables("SecondPartyID").Value = txtSecondPartyID
If txtParties = 3 then
.Variables("ThirdParty").Value = vbCr & "and" & vbCr &
txtThirdParty
.Variables("FirstPartyID").Value = txtThirdPartyID
End If
.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






- Show quoted text -

Doug thanx that's perfect but I already had that. The problem is how
do I stop having Errors in my word document as in the word document I
say {DOCVARIABLE Firstparty] {DOCVARIABLE SecondParty} which works
correct as those variables always exist. Then I have {DOCVARIABLE
Thirdparty} but if there are isn't a third party the DOCVARIABLES
gives an error in my document and it stays there. Therefore me asking
how do I programme the document to say if the variable exist place it
in the specific place in the document. If it doesn't exist, ignore it.
So if Docvariable thirdparty is "" ignore it. I hope you understand
what I am trying to say.
 

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

Similar Threads


Top