View Single Post
  #25   Report Post  
Murray Muspratt-Rouse Murray Muspratt-Rouse is offline
Member
 
Location: Mill Hill, London, England
Posts: 44
Default

The reason I commented out all the other lines of code was so as to make it easier to get back to where I was if the recommendations did not succeed in solving the problem. I will back up the database and do it again, removing all the code not included in your recommendations. Then, if it fails again, I will be able to restore the module from the backup.

I have done as I said I would above, with the same result. Here is the code that ran: -

Sub OpenWordDoc(strDocName As String, strLetterDescription As String, strFormName As String)
Dim objApp As Object
Dim objMMMD As Object
Dim strCurrentFileName As String
On Error Resume Next
DoCmd.OpenQuery "qrydeleteMergeTablerows"


'Load data to MergeTable with a query that collects the required data after update

If strFormName = "Volunteers" Then
If strLetterDescription = "REFERENCE REQUEST" Then
DoCmd.OpenQuery ("qryUpdateRefereeLetterDate")
DoCmd.OpenQuery ("qryReferees")
Else
If strLetterDescription = "Referee chaser" Then
DoCmd.OpenQuery ("qryUpdateRefereeChaserDate")
DoCmd.OpenQuery ("qryRefereechaser")
Else
DoCmd.OpenQuery ("qryVolunteer")
End If
End If
Else
DoCmd.OpenQuery ("qryClient")
End If

strCurrentFileName = CurrentDb.Name

Set objApp = CreateObject("Word.Application")
objApp.Activate
Set objMMMD = objApp.Documents.Open(FileName:=strDocName)

With objMMMD
.MailMerge.OpenDataSource Name:= _
strCurrentFileName, _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Connection:= _
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";Us er ID=Admin;Date Source=strCurrentFileName;Mode=Read;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDBatabase Password="""";Jet OLE" _
, SQLStatement:="SELECT * FROM `mergetable`", SQLStatement1:="", _
SubType:=wdMergeSubTypeAccess
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = .ActiveRecord
.LastRecord = .ActiveRecord
End With
.Execute Pause:=False
.Close wdDoNotSaveChanges
End With

End Sub


Murray

Quote:
Originally Posted by Doug Robbins - Word MVP View Post
I can see why you would comment out

'objApp.Visible = False

But why are you commenting out all of the other lines of code?

--
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

Last edited by Murray Muspratt-Rouse : August 29th 08 at 11:20 AM Reason: Completion of further test of code