472,119 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

Access Mail Merge to Word VBA Code Assistance

I want to write a VBA mail merge code. I want to link the code/macro/dohicky to a nifty little button so it makes life easy. I think I can handle the button part, the code part - not so much. I know very little (actually probably nothing) about VBA and I'm currently learning my way around Access.

Basically, I want to click a button in the form that merges the letter for me, only for the one record I'm currently viewing..not the whole database.

Here is what I have so far (shamelessly modified from the MS help site)

Public Function Merge3rdOffense()

Set obj = Word = GetObject("\\Ovpd2k2\Admin\Cassidy\Alarms\3rd Letter\0 NEW MAIL MERGE TEMPLATE.doc", "Word.Document")
'Make Word visible
obj.Word.Application.Visible = True
'Set the mail merge data source as the Alarms 2007 database
objWord.MailMerge.OpenDataSource _
Name:="C:\Progream Files\Microsoft " & _
"\\Ovpd2k2\Volunteer\alarms\Alarms 2007.mdb"
LinkToSource: =True, _
Connections:="QUERY 3rd Offense", _
SQLStatement:="SELECT * FROM (3rd Offense)"

'Execute the mail merge.

End Function

This part:
LinkToSource: =True, _
Connections:="QUERY 3rd Offense", _
SQLStatement:="SELECT * FROM (3rd Offense)"
seems to be my error (or at least I assume it is since it is in red).

I'ver been told we don't have a SQL server so that might be my issue, but again, I don't know enough about it to know how to modify this to work.

I'm using Access 2002 (ick I know) and Windows XP.

Alarms 2007 is my database

0 NEW MAIL MERGE TEMPLATE.doc is my merge doc (maybe the 0 is bad?)

There is a query called 3rd offense that I was hoping might make life easier (based on the MS example). It pulls only records with the Date Letter Sent field filled in with today's date. If I don't need the query, I'm OK with that.

Thanks for your help! Hopefully, I have enough info in there=/
Dec 28 '07 #1
1 4866
3,080 Expert 2GB
Try changing:

SQLStatement:="SELECT * FROM (3rd Offense)"


SQLStatement:="SELECT * FROM [3rd Offense]"

Dec 30 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by antonovaCCCS | last post: by
8 posts views Thread by Squirrel | last post: by
reply views Thread by gevayl | last post: by
6 posts views Thread by crealesmith | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.