aziz rasul
Active member
- Local time
- Today, 17:33
- Joined
- Jun 26, 2000
- Messages
- 1,935
I have the following code which errors on line
The error (Error has occurred: The database has been placed in a state by user 'Admin' on machine 'W74XXXXXX' that prevents it from being opened or locked) appears in the Word document.
Any ideas anyone how I resolve this?
Code:
.OpenDataSource Name:=CurrentProject.FullName, SQLStatement:="SELECT * FROM [qryMailMerge]"
Code:
Public Sub CreateWordToPDF(strWordFile As String, strPDFFile As String, strSQL As String)
'Call CreateWordToPDF("C:\Doc1.doc", "C:\Doc1.pdf", "SELECT * FROM [qryMailMerge]")
Dim objWord As Word.Application
Dim docWord As Word.Document
'Open MS Word using early binding.
Set objWord = New Word.Application
Set docWord = objWord.Documents.Open(strWordFile)
'Opening the MS Word template file.
With objWord
.Visible = True
.Activate
.Documents.Open (strWordFile)
End With
With objWord.ActiveDocument.MailMerge
.OpenDataSource Name:=CurrentProject.FullName, SQLStatement:="SELECT * FROM [qryMailMerge]"
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
'Export as PDF.
docWord.ExportAsFixedFormat OutputFileName:=strPDFFile, ExportFormat:=wdExportFormatPDF
objWord.Quit
Set objWord = Nothing
End Sub
Any ideas anyone how I resolve this?