473,549 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Output access to Word merge

Hello

On my Access database form I have a command button which opens a Word mail
merge document in which I have created a number of fields (Title, FirstName,
LastName, Address1 etc.)

I would like to be able to populate the Word document with the contents of
the currently selected Access record so that when I press the button in
Access, Word opens with the appropriate fields populated and ready to print.
It is a "one off" event which I will use, typically, to print a single
letter or invoice which is more easily edited in Word.

My code at the moment is:
-------
Private Sub StartWord_Click ()
On Error GoTo Err_StartWord_C lick

Dim LWordDoc As String
Dim oApp As Object

'Path to the word document
LWordDoc = "m:\database\po olshop\Invoice new.doc"

If Dir(LWordDoc) = "" Then
MsgBox "Document not found."

Else
'Create an instance of MS Word

Set oApp = CreateObject("W ord.Application ")
oApp.Visible = True

'Open the Document
oApp.Documents. Open FileName:=LWord Doc
End If

Exit_StartWord_ Click:
Exit Sub

Err_StartWord_C lick:
MsgBox Err.Description
Resume Exit_StartWord_ Click

End Sub
-------

But at the moment it does not automatically populate Word with anything, or
at least, by default, I see the contents of the first record. What I want is
to see, in my Word fields, the data from the current record. I can use the
normal mail merge search facility in Word to do a query and find the right
record but that is clumsy and I know you can do better.

I do not want to sound arrogant (be kind to me) but I do quite like the bit
of code that I have used (copied from elsewhere) and rather hope that all I
need to do is add a "current.record " type of command to it somewhere to get
the result that I need.

Thank you for your help, keep it simple.

Les
Nov 13 '05 #1
4 6272
On Sat, 12 Feb 2005 20:55:49 GMT, Dadio <da***@fred.net > wrote:
On my Access database form I have a command button which opens a Word
mail merge document in which I have created a number of fields (Title,
FirstName, LastName, Address1 etc.)

I would like to be able to populate the Word document with the contents
of the currently selected Access record so that when I press the button
in
Access, Word opens with the appropriate fields populated and ready to
print. It is a "one off" event which I will use, typically, to print a
single
letter or invoice which is more easily edited in Word.


I am working on this subject myself. Below is some code I have modified
based on the method espoused by Albert Kallal. It works, but is not
finished. You will need a document set up with mail merge fields that
correspond to a query:

Dim mWord As Object
Set mWord = CreateObject("W ord.Application ")

DoCmd.TransferT ext acExportDelim, , "LogSheetQuery" , "C:\log_sheet.t xt",
True

mWord.Documents .Open "c:\LogSheet.do c"
mWord.Applicati on.Visible = True
mWord.ActiveDoc ument.MailMerge .MainDocumentTy pe = wdFormLetters
mWord.ActiveDoc ument.MailMerge .OpenDataSource Name:="C:\log_s heet.txt", _
AddToRecentFile s:=False, Format:=0, Connection:="", SQLStatement:=" ",
SQLStatement1:= ""
mWord.ActiveDoc ument.MailMerge .Execute
Set mWord = Nothing

Darryl Kerkeslager
Nov 13 '05 #2
For a single output like that, I've had good success using a Word Template
with Bookmarks instead of a Mail Merge document.
Open a document based on the template (wrd.documents. add), and loop through
the bookmarks collection.
If you name the bookmarks the same as the controls on your Access form, it's
especially easy to write the code.

HTH
- Turtle

"Dadio" <da***@fred.net > wrote in message
news:p3******** *********@newsf e2-win.ntli.net...
Hello

On my Access database form I have a command button which opens a Word mail
merge document in which I have created a number of fields (Title, FirstName, LastName, Address1 etc.)

I would like to be able to populate the Word document with the contents of
the currently selected Access record so that when I press the button in
Access, Word opens with the appropriate fields populated and ready to print. It is a "one off" event which I will use, typically, to print a single
letter or invoice which is more easily edited in Word.

My code at the moment is:
-------
Private Sub StartWord_Click ()
On Error GoTo Err_StartWord_C lick

Dim LWordDoc As String
Dim oApp As Object

'Path to the word document
LWordDoc = "m:\database\po olshop\Invoice new.doc"

If Dir(LWordDoc) = "" Then
MsgBox "Document not found."

Else
'Create an instance of MS Word

Set oApp = CreateObject("W ord.Application ")
oApp.Visible = True

'Open the Document
oApp.Documents. Open FileName:=LWord Doc
End If

Exit_StartWord_ Click:
Exit Sub

Err_StartWord_C lick:
MsgBox Err.Description
Resume Exit_StartWord_ Click

End Sub
-------

But at the moment it does not automatically populate Word with anything, or at least, by default, I see the contents of the first record. What I want is to see, in my Word fields, the data from the current record. I can use the
normal mail merge search facility in Word to do a query and find the right
record but that is clumsy and I know you can do better.

I do not want to sound arrogant (be kind to me) but I do quite like the bit of code that I have used (copied from elsewhere) and rather hope that all I need to do is add a "current.record " type of command to it somewhere to get the result that I need.

Thank you for your help, keep it simple.

Les

Nov 13 '05 #3
You might find my example code does what you want, and then you don't have
to do anything!!

Give my sample word merge a try here:

http://www.members.shaw.ca/AlbertKal.../msaccess.html

The above example actually allows you to create, and merge word temples all
from inside of ms-access. What is also very nice is in fact their is NO HARD
coding of field names, and thus my solution works for all forms in your
application (I always hated book marks, as then you have actually write
code, and also hard code field names in your code!. Customers/clients tend
to find this dishonest, as then to make a new word merge document, you
actually have to bring in the developer!....a nd that don't look very
good!!).

Anther bonus of my mail merge stuff is that it defaults to merging only the
CURRENT record you are viewing.
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl************* ****@msn.com
http://www.members.shaw.ca/AlbertKallal
Nov 13 '05 #4
To Darryl, McDermott and Albert
Many many thanks for taking the trouble to reply so quickly.
I have spent about 5 hours searching the web for a solution to what I
thought must be a common everyday problem and just could not find a solution
that even came close to what was needed.
Now I find myself worshipping at the feet of Albert who has just about the
slickest fix I could ever have imagined. What is more amazing is that it is
simple and even I could follow the clear and well written, and illustrated
text to have the data up and running in just a few minutes.

So, Albert, you have just reached super-hero status and I can only say thank
you. Don't you ever close your web site. It is too important!

Obviously Darryl is familiar with your work and to Macdermott all I can say
is give the "Albert Method" a try. I did not like using bookmarks, it seems
like a method used by quite a few people but a bit clumsy.

Now I can sleep soundly.

Thank you Thank you.......

Les

"Albert D. Kallal" <ka****@msn.com > wrote in message
news:RIwPd.3711 44$Xk.295322@pd 7tw3no...
You might find my example code does what you want, and then you don't have
to do anything!!

Give my sample word merge a try here:

http://www.members.shaw.ca/AlbertKal.../msaccess.html

The above example actually allows you to create, and merge word temples all from inside of ms-access. What is also very nice is in fact their is NO HARD coding of field names, and thus my solution works for all forms in your
application (I always hated book marks, as then you have actually write
code, and also hard code field names in your code!. Customers/clients tend to find this dishonest, as then to make a new word merge document, you
actually have to bring in the developer!....a nd that don't look very
good!!).

Anther bonus of my mail merge stuff is that it defaults to merging only the CURRENT record you are viewing.
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl************* ****@msn.com
http://www.members.shaw.ca/AlbertKallal

Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3696
by: Ecohouse | last post by:
I have a computer with XP on it. I loaded Office 97 first because I needed Access 97 for some work. I then loaded Office 2000. Everything seemed to be running fine. But I have come across a few problems. 1) I have hyperlinks in some tables and when I try to access the hyperlinks I get an error message "An unexpected error has occurred. ...
9
4310
by: Neil Ginsberg | last post by:
I have a strange situation using Access to automate a Word mail merge. Using Access 2000 and Word 2000, the code opens Word, opens the document in Word, sets a table in the calling Access application as the data source, and then performs a merge. Everything works fine. However, when a user uses it in Access 2002 and Word 2002, an extra...
3
5570
by: Andy Davis | last post by:
I have set up a mail merge document in Word 2003 which gets its data from my Access 2000 database. I want to set up a button on a form that: 1. runs the query to provide the dat for the merge document in Word; 2. opens the document and runs the merge process for the new data. I have managed to write the code to perform step 1 ok, but I'm...
0
2168
by: Linda Cacina | last post by:
Hello all you fine folks, Here is some code I am using to merge data from a single record Access 2K3 table into a NEW word document based on a pre-defined Word merge template doc. All I want to happen is as follows: User defines a storage path and name for the new Word document then clicks a "Create" button on a form. From that point on...
4
7462
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...
1
4901
by: ashkash | last post by:
I have an access database which takes information from a user and then uses the mail merge functionality to merge the data into a word document. I have a lot of subforms in the access database which allows the user to keep entering data if they need to. By this I mean each subform is like a dynamic table (continous form view) and the user can keep...
8
13324
by: Ron B | last post by:
Help!!! What am I doing wrong? I am working with Office 2003 and am trying to create a command button on an Access form that will create a mail merge in Word from an Access table. I want to make the mail merge seamless to the user so all they have to do is click on the command button and the letters are generated. For the button I...
8
6688
by: babyangel43 | last post by:
Hello, I have a query set up in Access. I run it monthly, changing "date of test". I would like this query to be merged with a Word document so that the cover letter is created in Word, the fields from Access are automatically filled into the Word document. The query could be anywhere from 0-5000 names, one cover letter per name. AND to this...
1
6536
by: Esther Lane | last post by:
Hello! First off, many many thanks to Albert who wrote the Mail Merge code for MS Access I am using. It has been working beautifully for a few years. However, my client just (without notice!) upgraded from Access 2000 to Access 2007. Now that component is failing. The merge is building the data source file fine (text file named...
0
7720
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7957
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...
1
7470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5088
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...
0
3500
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...
1
1941
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
1
1059
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
763
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...

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.