The error message states 'ertProdInfo', rather than CertProdInfo. Is this a typo or is your merge looking for a different table name?
Getting an unexpected error in the code of a function
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:
However the table "CertProdInfo" does exist as you can see:
What am I doing wrong?
Thanks in advance.
Microsoft 365 and Office | Access | For home | Windows
2 answers
Sort by: Most helpful
-
Duane Hookom 26,525 Reputation points Volunteer Moderator
2025-09-06T23:10:56.2566667+00:00 -
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