Userforms

J

John

Hi,
I am new to word userforms and in need of some help.
I have created a document with a userform which has several text boxes for
data.
I have a command button which I would like to transpose the data to the open
document template.

First. How do I get the userform to popup when the document opens to accept
data input?

Second. How do I get the Data to transpose to the document from the
userform fields when I click the command button on the userform?

Third. Do I need to set fields or text boxes on the document to accept
data from the userform?

I hope you can see what I am trying to achieve here.

Regards

john
 
D

Doug Robbins - Word MVP

The form should be in a template and you would use the following code in an
autonew macro in that template to cause the userform to be displayed

Sub autonew()
'
Dim myForm As frmLetterForm 'Note in the case of this code, the form is
named frmLetterForm

Set myForm = New frmLetterForm
myForm.Show vbModal
Unload myForm
Set myForm = Nothing

End Sub

There are various ways to cause the information that is entered into the
userform to be displayed in the document. I prefer to use document
variables and { DOCVARIABLE varname }fields. This is typical of the code
that I use in a command button on the form to load the information into
document variables:

Set NewDoc = ActiveDocument
With NewDoc
If txtAddressee = "" Then
.Variables("varAddressee").Value = " "
Else
.Variables("varaddressee").Value = Trim(txtAddressee)
End If
If txtCompany = "" Then
.Variables("varCompany").Value = " "
Else
.Variables("varCompany").Value = Trim(txtCompany)
End If
If txtstreet = "" Then
.Variables("varaddress").Value = " "
Else
.Variables("varaddress").Value = Trim(txtstreet)
End If
If txtCity = "" Then
.Variables("varcity").Value = " "
Else
.Variables("varcity").Value = Trim(txtCity)
End If
If TxtState = "" Then
.Variables("varstate").Value = " "
Else
.Variables("varstate").Value = Trim(TxtState)
End If
If txtZip = "" Then
.Variables("varzip").Value = " "
Else
.Variables("varzip").Value = Trim(txtZip)
End If
If txtCountry = "" Then
.Variables("varcountry").Value = " "
Else
.Variables("varcountry").Value = Trim(txtCountry)
End If
If txtSubject = "" Then
.Variables("varSubject").Value = " "
Else
.Variables("varsubject").Value = Trim(txtSubject)
End If
If txtSignatory = "" Then
.Variables("varsignatory").Value = " "
Else
.Variables("varsignatory").Value = Trim(txtSignatory)
End If
If txtSalutation = "" Then
.Variables("varSalutation").Value = " "
Else
.Variables("varSalutation").Value = Trim(txtSalutation)
End If
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
 
J

John

Hi Doug,
Thanks for the reply.
Great stuff there. I will start work right now.

Kind Regards

John
 

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