Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 08-05-2024, 02:36 AM
catflap's Avatar
catflap catflap is offline Error 'An operation cannot be completed because of database engine errors' Windows 7 64bit Error 'An operation cannot be completed because of database engine errors' Office 2013
Advanced Beginner
Error 'An operation cannot be completed because of database engine errors'
 
Join Date: Aug 2015
Location: UK
Posts: 77
catflap is on a distinguished road
Default Error 'An operation cannot be completed because of database engine errors'

Hi




Hopefully this is posted in the right area - it's related to Access, but the essential problem is with Word:


I'm trying to automate the following on a series of Word docs from Access vba:



1. Open the word doc
2. Change data source
3. Merge to a pdf


I've got some code for changing the data source of a doc (which I got from from ChatGPT) which works fine for most circumstances:


Code:
Sub UpdateMailMergeDataSource(docPath As String, dataSourcePath As String, sqlQuery As String)
    
    Dim wdApp As Object
    Dim wdDoc As Object
    
    ' Open Word application
    On Error Resume Next
    Set wdApp = GetObject(, "Word.Application")
    If wdApp Is Nothing Then
        Set wdApp = CreateObject("Word.Application")
    End If
    On Error GoTo 0
    
    ' Open the Word document
    Set wdDoc = wdApp.Documents.Open(docPath)
    
    ' Update the data source
    With wdDoc.MailMerge
    .MainDocumentType = 0 ' wdFormLetters
    .OpenDataSource Name:=dataSourcePath, ConfirmConversions:=False, _
                    ReadOnly:=True, _
                    LinkToSource:=True, _
                    AddToRecentFiles:=False, _
                    PasswordDocument:="", _
                    PasswordTemplate:="", _
                    WritePasswordDocument:="", _
                    WritePasswordTemplate:="", _
                    Revert:=False, _
                    format:=0, Connection:="Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=" & dataSourcePath & ";Mode=Read;Extended Properties=""HDR=YES;IMEX=1"";", _
                    SQLStatement:=sqlQuery
    End With
    
    ' Save the document
    wdDoc.Save
    
    ' Close the document without prompting to save changes
    wdDoc.Close SaveChanges:=False
    
    ' Quit Word application if no other documents are open
    If wdApp.Documents.Count = 0 Then
        wdApp.Quit SaveChanges:=False
    End If
    
    ' Release objects
    Set wdDoc = Nothing
    Set wdApp = Nothing
End Sub

..however, it falls over when the doc has been linked to an excel file which has then been deleted (or has name changed). On oipening I get the error 'An operation cannot be completed because of database engine errors', which stops the code from carrying on.



The usual routine when when opening the doc manually would be to cancel the error, remove the merge source, and re-attach the new one.



So I'm looking for a way to ignore or cancel the errors which come up when you get an issue with datasource. After that the existing code should work.


Could anyone suggest a way to do this please?


Thanks!
Reply With Quote
 

Tags
mail merge, vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error 'An operation cannot be completed because of database engine errors' Office 365 conversion - Error 429 when opening Access database BruceM Word VBA 1 10-09-2018 06:22 AM
Error 'An operation cannot be completed because of database engine errors' Search Engine based on multiple critiria Macacidic Excel 14 09-09-2017 03:29 PM
MS Office 2013 error (lots of errors) Mr.Weck Office 8 01-04-2014 02:12 PM
Error 'An operation cannot be completed because of database engine errors' Associated operation ECPL_3 Excel 2 10-14-2010 05:29 PM
Error 'An operation cannot be completed because of database engine errors' Access database engine with Streets and Trips 2009 dreemsnake Misc 3 05-26-2009 10:25 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:07 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft