Printing Word Documents in Access

dsomers

Registered User.
Local time
Today, 11:01
Joined
Nov 13, 2003
Messages
131
Here's a thread I posted in the Word section. It probably should go in this section because I know its going to take some VB programming to get it done.

If anyone can help me or even point me in the right direction, I would really appreciate it!

Hello all! I'm working on some real estate management software and what my question is about is concerning printing forms that I have that are Word documents.

I have about 10 different Word documents that I have for new tenants. What I want to do is go to a dialog box and have the list of files there and be able to select a particular file and print it out with the information about the new tenant already included in the word document. Ideally what I'd like to do is have a button off of my switchboard that I can click and have it print those 10 documents out with the desired informtaion put in them automatically.

So far I've created my dialog box with my list box and command buttons. I'm just not sure how to incorporate these filenames into that list box and add the functionality to print with the desired information I want.

Any help that anyone can give me is deeply appreciated.

Thanks!
David Somers
 
Its been a while since I wrote this. At the time, I used '97.
Your word document(s) should be templates with word fields where you want access to insert data.
Your code will open the template, fill it in and save it under a defferent name - if you want to save a copy of the completed form. Otherwise, don't save the document. Here is code from a sub I called with all the variables. DO NOT FORGET TO CLOSE WORD!
Sub makeJPR(jprnew As String, keynew As String, orgnew As Date, intervalnew As Variant, xlatenew As String, banner As Integer)
Dim PathX, jprx, p1, p2, p3, P3t, P4, pcompt, pcomp, getarg
Dim dbs As Database, rst As Recordset, drst As Recordset
Dim strDoc As String, KTSKx As String
Dim mp1 As String, mp2 As String, mt As String, resp
Dim ncnt As Integer, wrd As Object, wrda As Object, plantx As String
mp1 = "MS Word Document - JPR" & jprnew & ".doc - already exists!"
Set wrda = CreateObject("Word.Application")
Set dbs = OpenDatabase(locatetables())
Set rst = dbs.OpenRecordset("TOC")
Set drst = dbs.OpenRecordset("dapiaxref")
p3 = "\JPR-" & jprnew & ".doc"
P3t = "\SJPR-" & jprnew & ".doc"
plantx = DLookup("[Mfg Ctr No]", "sysparameters", "sysparameters![recno]=1")
plantx = Trim(plantx)
p1 = DLookup("[JPRdrv]", "sysparameters", "sysparameters![recno]=1")
p1 = Format(p1)
p2 = DLookup("[JPRfldr]", "sysparameters", "sysparameters![recno]=1")
p2 = "\" & Format(p2)
pcomp = p1 & p2 & p3
pcompt = p1 & p2 & P3t
On Error Resume Next
getarg = Dir(pcomp)
If getarg <> "" Then
resp = MsgBox(mp1, vbExclamation)
GoTo out
End If
strDoc = p1 & p2 & "\XX" & Format(banner, "0") & "-99-99-9999.doc"
Set wrd = GetObject(, "Word.Application")
wrd.Documents.Open strDoc
wrd.Documents(strDoc).Activate
If wrd.ActiveDocument.Bookmarks.Exists("Text2") = True Then
wrd.ActiveDocument.FormFields("Text2").Result = Trim(plantx)
End If
If wrd.ActiveDocument.Bookmarks.Exists("Text3") = True Then
wrd.ActiveDocument.FormFields("Text3").Result = Trim(keynew)
End If
If wrd.ActiveDocument.Bookmarks.Exists("Text4") = True Then
wrd.ActiveDocument.FormFields("Text4").Result = Trim(jprnew)
End If
If wrd.ActiveDocument.Bookmarks.Exists("Text6") = True Then
wrd.ActiveDocument.FormFields("Text6").Result = makedapiastr(Me!Text10)
End If
If wrd.ActiveDocument.Bookmarks.Exists("Text11") = True Then
wrd.ActiveDocument.FormFields("Text11").Result = orgnew
End If
wrd.ActiveDocument.SaveAs FileName:=pcomp
If Trim(UCase(xlatenew)) = "SP" Then
'create Spanish document
strDoc = p1 & p2 & "\SXXX-99-99-9999.doc"
Set wrd = GetObject(, "Word.Application")
wrd.Documents.Open strDoc
wrd.Documents(strDoc).Activate
If wrd.ActiveDocument.Bookmarks.Exists("Text2") = True Then
wrd.ActiveDocument.FormFields("Text2").Result = Trim(plantx)
End If
If wrd.ActiveDocument.Bookmarks.Exists("Text3") = True Then
wrd.ActiveDocument.FormFields("Text3").Result = Trim(keynew)
End If
If wrd.ActiveDocument.Bookmarks.Exists("Text4") = True Then
wrd.ActiveDocument.FormFields("Text4").Result = Trim(jprnew)
End If
If wrd.ActiveDocument.Bookmarks.Exists("Text6") = True Then
wrd.ActiveDocument.FormFields("Text6").Result = makedapiastr(Me!Text10)
End If
If wrd.ActiveDocument.Bookmarks.Exists("Text11") = True Then
wrd.ActiveDocument.FormFields("Text11").Result = orgnew
End If
wrd.ActiveDocument.SaveAs FileName:=pcompt
End If
wrd.ActiveDocument.Close savechanges:=wdDoNotSaveChanges
wrda.Application.quit savechanges:=wdDoNotSaveChanges
wrd.Application.quit savechanges:=wdDoNotSaveChanges
Set wrd = Nothing
Set wrda = Nothing
This should give you the idea.
 

Users who are viewing this thread

Back
Top Bottom