I managed writing the letter ok, but can't figure out how to find the name the user saved it to so's I can pop that in the database. Heres my code. It's Access, but similar enough. All the me.things are controls on my form, but they may just as well be recordset things.
Sub WriteALetter()
'On Error GoTo ContactLetter_err
Dim cCompany As String
' Create an instance of Microsoft Word 97.
Set WordApp = CreateObject("Word.Application"
' Create a new, empty document.
Set WordDoc = WordApp.Documents.Add
WordApp.Visible = True
With WordApp.Selection
.TypeParagraph
.TypeParagraph
.TypeText Text:=Me.tMainName & " "
.TypeParagraph
If IsNull(Me.tCorresAdd1) Then
If Not IsNull(Me.tAddress1) Then
.TypeText Text:=Me.tAddress1 & " "
.TypeParagraph
End If
If Not IsNull(Me.tAddress2) Then
.TypeText Text:=Me.tAddress2 & " "
.TypeParagraph
End If
If Not IsNull(Me.tAddress3) Then
.TypeText Text:=Me.tAddress3 & " "
.TypeParagraph
End If
If Not IsNull(Me.tTown) Then
.TypeText Text:=Me.tTown & " "
.TypeParagraph
End If
If Not IsNull(Me.tCounty) Then
.TypeText Text:=Me.tCounty & " "
.TypeParagraph
End If
If Not IsNull(Me.tPostcode) Then
.TypeText Text:=Me.tPostcode & " "
.TypeParagraph
End If
Else
If Not IsNull(Me.tCorresAdd1) Then
.TypeText Text:=Me.tCorresAdd1 & " "
.TypeParagraph
End If
If Not IsNull(Me.tCorresAdd2) Then
.TypeText Text:=Me.tCorresAdd2 & " "
.TypeParagraph
End If
If Not IsNull(Me.tCorresAdd3) Then
.TypeText Text:=Me.tCorresAdd3 & " "
.TypeParagraph
End If
If Not IsNull(Me.tCorresTown) Then
.TypeText Text:=Me.tCorresTown & " "
.TypeParagraph
End If
If Not IsNull(Me.tCorrescounty) Then
.TypeText Text:=Me.tCorrescounty & " "
.TypeParagraph
End If
If Not IsNull(Me.tCorrespcode) Then
.TypeText Text:=Me.tCorrespcode & " "
.TypeParagraph
End If
End If
.TypeParagraph
' If IsNull(Me.Dear) Then
.TypeText Text:="Dear " & Me.tMainName & " "
' Else
' .TypeText Text:="Dear " & Me.Dear
' .TypeParagraph
' End If
.TypeText Text:=" "
.TypeParagraph
End With
' Show the instance of Microsoft Word.
WordApp.Visible = True
ContactLetter_ok:
Exit Sub
ContactLetter_err:
Resume ContactLetter_ok
End Sub