Printing Word docs from a button

  • Thread starter Thread starter Greg Casper
  • Start date Start date
G

Greg Casper

I have a button on a form and I want it to print a Word mail merge document
that contains data from the database that is linked to my application.

I'm using the following code but always get a 5922 error - Word can't open
the source... All variable names contain valid data, so that's NOT the
problem.

With appWord
.Visible = True
.Documents.Open pathdocname
With .ActiveDocument.MailMerge

.MainDocumentType = wdFormLetters
strConnection = "DSN=MS Access Databases;" _
& "DBQ=" & strFileName _
& "FIL=RedISAM;"
.OpenDataSource Name:=strFileName, LinkToSource:=True,
ReadOnly:=True, _
Connection:=strConnection, _
SQLStatement:="SELECT * FROM People WHERE !ContactID =
People.ContactID"
End With


Even if I take out the WHERE clause, it doesn't work. It just won't connect.

WHAT AM I DOING WRONG???

Thanks folks...
 
You "where" clause is defiantly wrong.... (word can't resolves forms
references to your current form...

However, as you mention, even without the where clause, it don't work.

You can give my sample a try here:

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

To merge the current record to a word document, you place behind a button
one command

MergeSingleWord

That is ALL you need to merge the current record.

if you want to print the document without any prompts, there are
instructions here:

http://www.members.shaw.ca/AlbertKallal/wordmerge/page2.html

Give the sample a try...
 
Back
Top