Could anyone help me sort this out. My database inputs records into a template document in word. I have the template set up with bookmarks, but as soon as there is a blank record, the whole process stops. This is what I have been using
There need to be blank records and I have also tried
but this code isn't adding the fields in the correct places, and I have no idea why!
Please please please would someone have a look at this for me!!
Code:
Private Sub MergeButton_Click()
'Start Microsoft Word 97.
Set objWord = CreateObject("Word.Application")
With objWord
'Make the application visible.
.Visible = True
'Open the document.
.Documents.Open ("\\Globalinfra.net\Teams\AW_LI_OMC\Private\Water\Regional Networks\Modellers\Database\Proforma for Modelling Results Template")
'Move to each bookmark and insert text from the form.
objWord.ActiveDocument.Bookmarks("Requested").Select
objWord.selection.Text = Forms![Modelling Results 2 - All]![Requested By]
objWord.ActiveDocument.Bookmarks("Business").Select
objWord.selection.Text = Forms![Modelling Results 2 - All]![Business Unit]
objWord.ActiveDocument.Bookmarks("DateRequested").Select
objWord.selection.Text = Forms![Modelling Results 2 - All]![Date Requested]
objWord.ActiveDocument.Bookmarks("DateRequired").Select
objWord.selection.Text = Forms![Modelling Results 2 - All]![Date Required]
objWord.ActiveDocument.Bookmarks("Details").Select
objWord.selection.Text = Forms![Modelling Results 2 - All]![Modelling Request Text]
objWord.ActiveDocument.Bookmarks("DMA").Select
objWord.selection.Text = Forms![Modelling Results 2 - All]![DMA's Affected]
objWord.ActiveDocument.Bookmarks("DZ").Select
objWord.selection.Text = Forms![Modelling Results 2 - All]![DZ Affected]
objWord.ActiveDocument.Bookmarks("Grid").Select
objWord.selection.Text = Forms![Modelling Results 2 - All]![Grid Reference]
objWord.ActiveDocument.Bookmarks("Location").Select
objWord.selection.Text = Forms![Modelling Results 2 - All]![Location of Work]
objWord.ActiveDocument.Bookmarks("Model").Select
objWord.selection.Text = Forms![Modelling Results 2 - All]![Model Used]
objWord.ActiveDocument.Bookmarks("Requestno").Select
objWord.selection.Text = Forms![Modelling Results 2 - All]![OMC Number]
objWord.ActiveDocument.Bookmarks("SAP").Select
objWord.selection.Text = Forms![Modelling Results 2 - All]![SAP Work Order Number]
objWord.ActiveDocument.Bookmarks("Type").Select
objWord.selection.Text = Forms![Modelling Results 2 - All]![Type of Work]
objWord.ActiveDocument.Bookmarks("Score").Select
objWord.selection.Text = Forms![Modelling Results 2 - All]![DMA Score]
objWord.ActiveDocument.Bookmarks("Network").Select
objWord.selection.Text = Forms![Modelling Results 2 - All]![Network Manager Area]
objWord.ActiveDocument.Bookmarks("Contact").Select
objWord.selection.Text = Forms![Modelling Results 2 - All]![Contact Number]
objWord.ActiveDocument.Bookmarks("Capital").Select
objWord.selection.Text = Forms![Modelling Results 2 - All]![Capital Code]
objWord.ActiveDocument.Bookmarks("Completedby").Select
objWord.selection.Text = Forms![Modelling Results 2 - All]![Modeller]
End With
End Sub
There need to be blank records and I have also tried
Code:
If IsNull(forms![Modelling Results]![DZ Affected]) = True Then
objWord.ActiveDocument.Bookmarks("DZ").Select
objWord.selection.Text =""
Else
objWord.ActiveDocument.Bookmarks("DZ").Select
ObjWord.Selection.Text = Forms![Modelling Results]![DZ Affected]
End If
but this code isn't adding the fields in the correct places, and I have no idea why!
Please please please would someone have a look at this for me!!