I am still having the same problem. When I go into Task Manager I can see that Word and Access are processing something, but no word doc comes up, and I can't do anything on Access
Main Topics
Browse All TopicsI am trying to output some fields from a form to a word template (both are from Office 2007). The problem I am getting is that I click the button and Access freezes. It doesn't crash, but you can't do anything. I am using the code I got from the related question.
My version is posted below.
Private Sub btnCreateLetter_Click()
Set strfrom = Me.OrderPickUp
Set strto = Me.OrderDestination
Set strdate = Me.OrderDate
Set strtype = Me.WCCType
Set strcosttpe = Me.WCCCostType
Set strboxes = Me.WBox
Set strcostboxes = Me.WCostBox
Set strtotalex = Me.WTotalEx
Set strtotalgst = Me.WTotalGST
Set Strtotalincl = Me.WTotalInc
Set wApp = CreateObject("Word.Applica
Set wDoc = wApp.Documents.Add(Templat
For Each wSec In wDoc.Sections
For Each wPara In wSec.Range.Paragraphs
Select Case True
Case InStr(1, wPara.Range.Text, "{from}") > 0
wPara.Range.Text = Replace(wPara.Range.Text, "{from}", strfrom)
Case InStr(1, wPara.Range.Text, "{to}") > 0
wPara.Range.Text = Replace(wPara.Range.Text, "{to}", strto)
Case InStr(1, wPara.Range.Text, "{date}") > 0
wPara.Range.Text = Replace(wPara.Range.Text, "{date}", strdate)
Case InStr(1, wPara.Range.Text, "{time}") > 0
wPara.Range.Text = Replace(wPara.Range.Text, "{time}", strtime)
Case InStr(1, wPara.Range.Text, "{type}") > 0
wPara.Range.Text = Replace(wPara.Range.Text, "{tyoe}", strtype)
Case InStr(1, wPara.Range.Text, "{costtype}") > 0
wPara.Range.Text = Replace(wPara.Range.Text, "{costtype}", strcosttype)
Case InStr(1, wPara.Range.Text, "{boxes}") > 0
wPara.Range.Text = Replace(wPara.Range.Text, "{boxes}", strboxes)
Case InStr(1, wPara.Range.Text, "{costboxes}") > 0
wPara.Range.Text = Replace(wPara.Range.Text, "{costboxes}", strcostboxes)
Case InStr(1, wPara.Range.Text, "{totalex}") > 0
wPara.Range.Text = Replace(wPara.Range.Text, "{totalex}", strtotalex)
Case InStr(1, wPara.Range.Text, "{totalgst}") > 0
wPara.Range.Text = Replace(wPara.Range.Text, "{totalgst}", strtotalgst)
Case InStr(1, wPara.Range.Text, "{totalincl}") > 0
wPara.Range.Text = Replace(wPara.Range.Text, "{totalincl}", Strtotalincl)
End Select
Next
Next
wApp.Visible = True
End Sub
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
As a test, try this
firstly move this higher up
wApp.Visible = True
maybe after object created
secondly remove the code within the loop starting with
For Each wSec In wDoc.Sections
This is to try rule out whether issue is opening word or the template or working within the doc.
If you are comfortable with debugging, place a breakpoint where you create the word object (f9), then step thru (f8), see where it goes cillit bang!
Moving up the wApp.Visible helped me find out where the loop was going wrong. I had a few typos in the actual code so it wasn't finding the text in the template.
I have another quick question which if you know the answer to I am willing to chuck up another question for but I was wonder, when the word file opens its called "Document1". Is there a way to make it automatically called something else depending on what my fields are.
For eg. it would be called "{date}-{name}"
Business Accounts
Answer for Membership
by: NatchiketPosted on 2009-04-11 at 00:02:41ID: 24121089
Set strfrom = Me.OrderPickUp
Set strto = Me.OrderDestination
Set strdate = Me.OrderDate
Set strtype = Me.WCCType
Set strcosttpe = Me.WCCCostType
Set strboxes = Me.WBox
Set strcostboxes = Me.WCostBox
Set strtotalex = Me.WTotalEx
Set strtotalgst = Me.WTotalGST
Set Strtotalincl = Me.WTotalInc
strTo,tDate etc are (or should be) string variables. Do not use the Set command. it should be
strDate = Me.orderdate
etc