Hi
I'm new to this so please bear with me ... hope someone can shed some light ...
I have a database that contains contact information (name, company, address etc.) together with requirements for those contacts e.g. Mr Bloggs requires property of a certain size in a certain area. We run a filter on the size and area to get a list of contacts that fit the requirements and these can be mailed out. I looked into mail merge but it can't be done from a form so created a command button that sends the contact information to a word template for mailing. The problem is that it only sends the information for the record I'm in, not for all of the filtered records (does that make sense?)
Is there a way of sending all the filtered information to word without having to do one at a time?
This is the code I have for the command button:
Private Sub MergeButton_Click()
On Error GoTo MergeButton_Err
Dim objWord As Word.Application
'Start Microsoft Word 2000.
Set objWord = CreateObject("Word.Application")
With objWord
'Make the application visible.
.Visible = True
'Open the document.
.Documents.Open ("E:\Grainne\Test Mail Merge.doc")
'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("Name").Select
.Selection.Text = (CStr(Forms!InvestorDetails!Title))
.ActiveDocument.Bookmarks("FirstName").Select
.Selection.Text = (CStr(Forms!InvestorDetails!FirstName))
.ActiveDocument.Bookmarks("LastName").Select
.Selection.Text = (CStr(Forms!InvestorDetails!LastName))
.ActiveDocument.Bookmarks("JobTitle").Select
.Selection.Text = (CStr(Forms!InvestorDetails!JobTitle))
.ActiveDocument.Bookmarks("Company").Select
.Selection.Text = (CStr(Forms!InvestorDetails!CCompany))
.ActiveDocument.Bookmarks("Address1").Select
.Selection.Text = (CStr(Forms!InvestorDetails!Address1))
.ActiveDocument.Bookmarks("Address2").Select
.Selection.Text = (CStr(Forms!InvestorDetails!Address2))
If IsNull(Forms!InvestorDetails![Address2]) Then
.Selection.TypeText ""
.Selection.TypeBackspace ' Delete this bookmark!
Else
.Selection.TypeText Forms!InvestorDetails![Address2]
End If
.ActiveDocument.Bookmarks("Address3").Select
.Selection.Text = (CStr(Forms!InvestorDetails!Address3))
If IsNull(Forms!InvestorDetails![Address3]) Then
.Selection.TypeText ""
.Selection.TypeBackspace ' Delete this bookmark!
Else
.Selection.TypeText Forms!InvestorDetails![Address3]
End If
.ActiveDocument.Bookmarks("City").Select
.Selection.Text = (CStr(Forms!InvestorDetails!City))
If IsNull(Forms!InvestorDetails![City]) Then
.Selection.TypeText ""
.Selection.TypeBackspace ' Delete this bookmark!
Else
.Selection.TypeText Forms!InvestorDetails![City]
End If
.ActiveDocument.Bookmarks("PostalCode").Select
.Selection.Text = (CStr(Forms!InvestorDetails!PostalCode))
.ActiveDocument.Bookmarks("Title").Select
.Selection.Text = (CStr(Forms!InvestorDetails!Title))
.ActiveDocument.Bookmarks("Last").Select
.Selection.Text = (CStr(Forms!InvestorDetails!LastName))
End With
MergeButton_Err:
'If a field on the form is empty, remove the bookmark text, and
'continue.
If Err.Number = 94 Then
objWord.Selection.Text = ""
Resume Next
End If
Exit Sub
End Sub
Help would be much appreciated as I'm sure I've read the whole forum looking for answers!
Grainne
I'm new to this so please bear with me ... hope someone can shed some light ...
I have a database that contains contact information (name, company, address etc.) together with requirements for those contacts e.g. Mr Bloggs requires property of a certain size in a certain area. We run a filter on the size and area to get a list of contacts that fit the requirements and these can be mailed out. I looked into mail merge but it can't be done from a form so created a command button that sends the contact information to a word template for mailing. The problem is that it only sends the information for the record I'm in, not for all of the filtered records (does that make sense?)
Is there a way of sending all the filtered information to word without having to do one at a time?
This is the code I have for the command button:
Private Sub MergeButton_Click()
On Error GoTo MergeButton_Err
Dim objWord As Word.Application
'Start Microsoft Word 2000.
Set objWord = CreateObject("Word.Application")
With objWord
'Make the application visible.
.Visible = True
'Open the document.
.Documents.Open ("E:\Grainne\Test Mail Merge.doc")
'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("Name").Select
.Selection.Text = (CStr(Forms!InvestorDetails!Title))
.ActiveDocument.Bookmarks("FirstName").Select
.Selection.Text = (CStr(Forms!InvestorDetails!FirstName))
.ActiveDocument.Bookmarks("LastName").Select
.Selection.Text = (CStr(Forms!InvestorDetails!LastName))
.ActiveDocument.Bookmarks("JobTitle").Select
.Selection.Text = (CStr(Forms!InvestorDetails!JobTitle))
.ActiveDocument.Bookmarks("Company").Select
.Selection.Text = (CStr(Forms!InvestorDetails!CCompany))
.ActiveDocument.Bookmarks("Address1").Select
.Selection.Text = (CStr(Forms!InvestorDetails!Address1))
.ActiveDocument.Bookmarks("Address2").Select
.Selection.Text = (CStr(Forms!InvestorDetails!Address2))
If IsNull(Forms!InvestorDetails![Address2]) Then
.Selection.TypeText ""
.Selection.TypeBackspace ' Delete this bookmark!
Else
.Selection.TypeText Forms!InvestorDetails![Address2]
End If
.ActiveDocument.Bookmarks("Address3").Select
.Selection.Text = (CStr(Forms!InvestorDetails!Address3))
If IsNull(Forms!InvestorDetails![Address3]) Then
.Selection.TypeText ""
.Selection.TypeBackspace ' Delete this bookmark!
Else
.Selection.TypeText Forms!InvestorDetails![Address3]
End If
.ActiveDocument.Bookmarks("City").Select
.Selection.Text = (CStr(Forms!InvestorDetails!City))
If IsNull(Forms!InvestorDetails![City]) Then
.Selection.TypeText ""
.Selection.TypeBackspace ' Delete this bookmark!
Else
.Selection.TypeText Forms!InvestorDetails![City]
End If
.ActiveDocument.Bookmarks("PostalCode").Select
.Selection.Text = (CStr(Forms!InvestorDetails!PostalCode))
.ActiveDocument.Bookmarks("Title").Select
.Selection.Text = (CStr(Forms!InvestorDetails!Title))
.ActiveDocument.Bookmarks("Last").Select
.Selection.Text = (CStr(Forms!InvestorDetails!LastName))
End With
MergeButton_Err:
'If a field on the form is empty, remove the bookmark text, and
'continue.
If Err.Number = 94 Then
objWord.Selection.Text = ""
Resume Next
End If
Exit Sub
End Sub
Help would be much appreciated as I'm sure I've read the whole forum looking for answers!
Grainne