473,373 Members | 1,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,373 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.
objWord.MailMerge.Execute

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 5023
nico5038
3,080 Expert 2GB
Try changing:

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

into

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

Nic;o)
Dec 30 '07 #2

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

Similar topics

1
by: antonovaCCCS | last post by:
In our old VB 6 application we utilize a mail merge feature of Word 97 with MS Access. A table in Access is populated from VB and a Word template is wired to that table. So all we do in the code is...
4
by: Tom Dauria | last post by:
I have an application that will be distributed remotely. In the Access application I am opening Word documents and mail merging. The Word documents are linked to a tmpLetter table. In my code I...
8
by: Squirrel | last post by:
Hi everyone, I've created a mail merge Word doc. (using Office XP) , the data source is an Access query. Functionality I'm attempting to set up is: User sets a boolean field to true for...
0
by: gevayl | last post by:
Hi, I used to have this Template in word that would have a bunch of bookmarks. Then in access I used to be able to, at the click of a button, replace those bookmarks(not merge fields) in word with...
4
by: pmhaupt2 | last post by:
I developed an Access 2003 program that will allow the user to produce a group of Word letters that merge with data records from an Access database. I created a mail merge Word document and...
0
by: mbbostwick | last post by:
I have a problem with a mail merge procedure I used to use with Access '97. We recently converted to Office XP (2002) and I now have an issue I am unfamilliar with and have been unable to...
6
by: crealesmith | last post by:
Firstly, I have no problem with mail merging to Word, VB code for that works perfectly. On one mail merge I need to merge 15 fields of data that are from 3 seperate records. The 3 records are all...
1
by: mbigelow | last post by:
I'm trying to create an e-mail statement that pulls data from two tables....one table is simply the Student information (e-mail, name, phone etc) and the other table is a Transaction table that can...
2
by: lostdog | last post by:
Hi, After searching through this forum I came across a link to the excellent Albert Kallal's super easy mail merge. It is really good though it seems that the only bound columns from a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.