Print out a word documents

  • Thread starter Thread starter martin
  • Start date Start date
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
 
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/
 
Back
Top