Print out a word documents

M

martin

I have created a button on a form to print infomation on
to a word template. Below is the shortened version of the
code. When ran, it go through to the end however it prints
out nothing onto the word document. You can get the code
to work but you have to replace the strName variable in
the SQL statement with an actual Name. Is it the case that
I can not use a variable in an SQL stsatement or have I
gone about it the wrong way???



Thanks In Advance

Martin



Dim rstPrintOut As New ADODB.Recordset
Dim AppWord As New Word.Application
Dim strName As String

strName = Me.txtCustomerName

rstWorkAllPrintOut.Open "SELECT * from
tblPolicyHolders where phName LIke 'strName'", _
CurrentProject.Connection, adOpenStatic,
adLockOptimistic

AppWord.Documents.Add "\\PC1\Temps\~Mandate.dot"

With AppWord

.ActiveDocument.ShowSpellingErrors = False
.Selection.GoTo wdGoToBookmark, Name:="bmkAddress"
.Selection.TypeText rstPrintOut!phAddress

AppWord.Visible = True

End With
 
M

Mark Phillipson

Hi,

When using the Like operator you should also use * (any characters) or ?
(ant character) or if you are using ADO/Server data use % or _

If it should be a straight match then don't use Like, use = instead.


Hope this helps


--

Cheers
Mark

Free Access/Office Add-Ins at:
http://mphillipson.users.btopenworld.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top