Getting an unexpected error in the code of a function

Maxine Nietz 1 Reputation point
2025-09-06T19:17:29.2733333+00:00

I have a function to perform a MailMerge as follows:

Function PrepForWord()

Dim objWord As Word.Application

Dim objDoc As Word.Document

Dim objMailMerge As Word.MailMerge

DoCmd.SetWarnings False

DoCmd.OpenQuery "CertInfo2"

DoCmd.OpenQuery "CertInfo3" - these queries create the table CertProdInfo

DoCmd.SetWarnings True

Set objWord = CreateObject("Word.Application")

objWord.Visible = True ' Set to True if you want to see Word open

Set objDoc = objWord.Documents.Open("C:\Users\nevadamax\OneDrive\Documents\USWelding\CertificationReport.docx")

Set objMailMerge = objDoc.MailMerge

objMailMerge.MainDocumentType = wdFormLetters

objMailMerge.OpenDataSource Name:="C:\Users\nevadamax\OneDrive\Documents\USWelding\MATERIALS2016CERT.accdb", SQLStatement:="SELECT * FROM CertProdInfo"

objMailMerge.Execute

End Function

I am getting the following error on the bolded line:

MergeError

However the table "CertProdInfo" does exist as you can see:

TableExists

What am I doing wrong?

Thanks in advance.

Microsoft 365 and Office | Access | For home | Windows
{count} votes

2 answers

Sort by: Most helpful
  1. Duane Hookom 26,525 Reputation points Volunteer Moderator
    2025-09-06T23:10:56.2566667+00:00

    The error message states 'ertProdInfo', rather than CertProdInfo. Is this a typo or is your merge looking for a different table name?


  2. Duane Hookom 26,525 Reputation points Volunteer Moderator
    2025-09-07T14:21:30.7033333+00:00

    I don’t use OpenQuery to execute action queries. This is the syntax I use

    CurrentDb.Execute "CertInfo2", dbFailOnError
    
    CurrentDb.Execute "CertInfo3", dbFailOnError
    
    
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.