473,756 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access Mail Merge to Word VBA Code Assistance

1 New Member
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("\\Ov pd2k2\Admin\Cas sidy\Alarms\3rd Letter\0 NEW MAIL MERGE TEMPLATE.doc", "Word.Document" )
'Make Word visible
obj.Word.Applic ation.Visible = True
'Set the mail merge data source as the Alarms 2007 database
objWord.MailMer ge.OpenDataSour ce _
Name:="C:\Progr eam Files\Microsoft " & _
"\\Ovpd2k2\Volu nteer\alarms\Al arms 2007.mdb"
LinkToSource: =True, _
Connections:="Q UERY 3rd Offense", _
SQLStatement:=" SELECT * FROM (3rd Offense)"

'Execute the mail merge.
objWord.MailMer ge.Execute

End Function

This part:
LinkToSource: =True, _
Connections:="Q UERY 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 5058
nico5038
3,080 Recognized Expert Specialist
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
2873
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 call the merge method of Word. Problem: We are moving to VB.NET (VS 2005) and Office 2003. I want to bypass Access and either use a connection to SQL or a parametrized stored procedure. I found some samples, but was not able to open the...
4
8878
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 write the records to be merged into that table. The Word documents are using a system dsn (ODBC) to connect to the data source. In my code I simply open the Word documents after writing to the table do a mail merge and print. It runs pretty...
8
9523
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 each person for whom a mail merge letter is desired. The query reads address info from the table for each record where is true.
0
1217
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 data from access query or form. I think it must have been a query. Anyhow I forgot how to do this, and lost all files/tutorials. If anyone knows a site that explains how to do this I would appreciate a post. Thanks.
4
7472
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 associated it with a specific query in my Access database. My problem is that when I run my "create letters" button from an Access form, the program opens up Word correctly with the proper letter. However, the MailMerge toolbar in Word appears...
0
2201
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 resolve. I am trying to merge individual records into seperate mail merge word docs. In the past I linked my word files directly to the tables and then simply changed the QueryString of the merge file for the particular record I need to create a...
6
4648
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 in the same table. If I use a control source that is selecting the 3 records, all of the data is shown but spread over 3 pages in the mail merge, but needs to be listed together in one paragraph. Is there anyway of looping through the 3...
1
1983
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 have multiple rows per student. Using Word mail merge I'm able to send a single e-mail to each entry in the Student table, however in the body of the e-mail I'd like to include the Student's transactions. Students - Transactions is a one to many...
2
1202
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 table can be merged, does anyone know of a way to merge information from unbound columns from linked tables into a word document?
0
9455
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9271
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9869
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8709
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5140
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3354
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2665
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.