UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Word Merge Via Macro, Access 2016    
 
   
jotoya
post Mar 13 2019, 04:12 PM
Post#1



Posts: 137
Joined: 17-May 16



Good afternoon,

I would like for my users to bring up the "Word Merge" feature in Access through a macro. I found this MS KB example and modified it to fit my needs but it refuses to open the data source. I originally wanted to move away from MS' example of using an external data source such as the Northwind DB so I set my current db as the data source (commented out below) and a query - no go. Then I tried the BE with tables - nothing.

I would greatly appreciate any guidance/help. Thank you much.


CODE
Function MergeIt()
Dim objWord As Word.Document
Dim curDBName As String

    'curDBName = CurrentDb.Name
    Set objWord = GetObject("C:\Users\Me\Desktop\MyMerge.docx", "Word.Document")
   ''' Make Word visible.
   objWord.Application.Visible = True
   '''' Set the mail merge data source as my database.
   objWord.MailMerge.OpenDataSource Name:="C:\Users\Me\Desktop\RLS_Tracker_BE.accdb", _
      LinkToSource:=True, _
      Connection:="Table PHTComplianceT", _
      SQLStatement:="SELECT * FROM [EmailID]"
   ''' Execute the mail merge.
  objWord.MailMerge.Execute
  Set objWord = Nothing
End Function
Go to the top of the page
 
GroverParkGeorge
post Mar 18 2019, 08:40 PM
Post#2


UA Admin
Posts: 35,683
Joined: 20-June 02
From: Newcastle, WA


"SQLStatement:="SELECT * FROM [EmailID]"

That does not look like a valid SQL String. EMailID would be the field, not the table, correct?

--------------------
My Real Name Is George. Grover Park Consulting is where I do business.
How to Ask a Good Question
Beginning SQL Server
Go to the top of the page
 
MadPiet
post Mar 18 2019, 10:49 PM
Post#3



Posts: 3,299
Joined: 27-February 09



Does anybody know if Albert Kallal's Super Easy Word Merge code works on Access 2016? As I'm stupid lazy (or just hate reinventing the wheel), I'd see if that worked before driving myself nuts trying to sort this out.
Go to the top of the page
 
jotoya
post Mar 18 2019, 11:04 PM
Post#4



Posts: 137
Joined: 17-May 16



THANK YOU GroverParkGeorge - You were 1000% correct. I am mortified! ::face palm::

A follow up if I may: Is there a way to reference a 'Query' instead of connecting to my BE table?
Go to the top of the page
 
GroverParkGeorge
post Mar 19 2019, 05:33 AM
Post#5


UA Admin
Posts: 35,683
Joined: 20-June 02
From: Newcastle, WA


I think you'd just need to change the syntax to refer to the query "SELECT * FROM qryYourQueryNameGoesHere"

--------------------
My Real Name Is George. Grover Park Consulting is where I do business.
How to Ask a Good Question
Beginning SQL Server
Go to the top of the page
 
jotoya
post Mar 19 2019, 09:20 AM
Post#6



Posts: 137
Joined: 17-May 16



Thank you much George.

Actually I had tried that but Access throws a run-time error - 5922 "Word was unable to open the data source."


Could it be that since the code "objWord.MailMerge.OpenDataSource Name:=" points to the back end file of the DB and its connection is to the table it doesn't "know" where to go?
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    20th September 2019 - 01:34 PM