473,382 Members | 1,545 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,382 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 5024
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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.