Hi,

I am using Excel VB Editor to create a macro that can be used to generate different letters onto a word document. This part is fine.

I need to be able to generate a different letter based on the input from the user.

For example, the text in the letter will be different if there has been contact with the customer as opposed to no contact with the customer.

It's like an if statement - How do I insert this into the code...I've attached my code below and your help would be greatly appreciated..

[VBA]
Private Sub cmdGenerate1_Click()
With UserForm
strDate1 = txtDate1.Text
strSalutation1 = cboSalutation1.Text
strFname1 = txtFName1.Text
strSurname1 = txtSurname1.Text
strAddress11 = txtAddress11.Text
strAddress12 = txtAddress12.Text
strRefNo1 = txtRefNo1.Text
strPhoneContact1 = cboPhoneContact1.Text
strContactedOn1 = txtContactedOn1.Text
strFrom1 = txtFrom1.Text
strTo1 = txtTo1.Text
strFrom2 = txtFrom2.Text
strTo2 = txtTo2.Text
strFrom3 = txtFrom3.Text
strTo3 = txtTo3.Text
strFrom4 = txtFrom4.Text
strTo4 = txtTo4.Text
strCaseNumber = txtCaseNumber.Text
End With
Set appWord = CreateObject("Word.Application")
'Makes Word visible, adds a new document and
'sets the margins & font name/size
With appWord
.Visible = True
.WindowState = 1 'Maximised
.Documents.Add
.ActiveWindow.ActivePane.View.ShowAll = False 'turn off non-printing characters
.ActiveDocument.PageSetup.LeftMargin = "1"
.ActiveDocument.PageSetup.RightMargin = "1"
.Selection.WholeStory
With .Selection.Font
.Name = "Courier New"
.Size = "10"
End With
'Set up the outline of the text doc
.Selection.insertafter UserForm.cboSalutation1 & " " & UserForm.txtFName1 & " " & UserForm.txtSurname1 & Chr(13)
.Selection.insertafter UserForm.txtAddress11 & Chr(13) & UserForm.txtAddress12 & Chr(13)
.Selection.insertafter Chr(13)
.Selection.insertafter strDate1 & Chr(13) & Chr(13)
.Selection.insertafter "Dear " & strFname1 & "," & Chr(13) & Chr(13)
.Selection.insertafter "CHANGES TO YOUR RECORD" & Chr(13) & Chr(13)
.Selection.insertafter "As we discussed with you on " & strContactedOn1 & ", we are writing to advise"
.Selection.insertafter " you of changes to income information in your record for "
.Selection.insertafter strFrom1 & " to " & strTo1 & " in case number " & strCaseNumber

Set appWord = Nothing
End With
Range("A1").Select
End Sub
Private Sub MultiPage1_Change()
End Sub
Private Sub txtRefNo1_Change()
If txtRefNo1 = vbNullString Then Exit Sub
If Not IsNumeric(txtRefNo1) Then
MsgBox "Only numeric values accepted"
txtRefNo1 = vbNullString
End If
End Sub
Private Sub txtTo1_Change()
End Sub
Private Sub UserForm_Initialize()
Application.Visible = True
txtFName1.Value = ""
txtSurname1.Value = ""
txtAddress11.Value = ""
txtAddress12.Value = ""
txtRefNo1.Value = ""
txtContactedOn1.Value = ""
With cboSalutation1
.AddItem "Mr"
.AddItem "Mrs"
.AddItem "Ms"
End With
cboSalutation1.Value = ""

With cboPhoneContact1
.AddItem "Y"
.AddItem "N"
End With
cboPhoneContact1.Value = ""
Me.txtDate1.Text = Format(Date, "Medium Date")
End Sub
[/VBA]