Suddenly, my code for mail merging to Word2k from Access2k has stopped working properly. This is the code, which up until now has worked perfectly.
Public Function DoALetter()
On Error GoTo ErrorHandler
Dim msg As Long
Dim myApp As Word.Document
If strActualDoc “invoice.doc” Then
If strActualDoc “Astandard.doc” Then
If IsLoaded(“PrintItems”) Then
If IsNull(Forms!PrintItems!Number) Then
MsgBox “YOU MUST INSERT A NUMBER FOR CONTACT!”, vbExclamation, “No Number!”
Exit Function
End If
End If
End If
End If
DoCmd.TransferText acExportMerge, , strQuery, strData, True
If (IsLoaded(“PrintItems”)) Then
DoCmd.Close acForm, “PrintItems”
End If
Set myApp = GetObject(strFolderDoc, “Word.Document”)
With myApp
.Application.Visible = True
.MailMerge.Destination = wdSendToNewDocument
.MailMerge.Execute
.Close (WdSaveOptions.wdDoNotSaveChanges)
End With
ErrorHandlerexit:
Exit Function
ErrorHandler:
MsgBox “Error No: ” & Err.Number & ” – ” & Err.Description
Resume ErrorHandlerexit
End Function
It still actually functions but the TransferText action will not transfer ‘strData’ to its text file because it thinks it is read-only (which it is not). If I delete the text file first, the function will create it again when it is run once. After that it won’t run again because it thinks the file is read-only again.
I should explain that the Word letters have a merge link to this text file as their data source. I find this easier to keep the permanent link and just change the data in the text file.
Does any one know why it suddenly thinks the file is read-only? Can I run a delete or move file from within the code ( like a DOS batch file)?
Incidentally, the only change that has occurred is that I just updated from Windows 95 to Windows 2k Pro.
Any advice would be very much appreciated. Thanks.
Peter H