Object required.

K

Kenny G

Hello,

Using Access 2002/Word 2002

I have an Access DB and a Word.dot letter. The user of the Access DB fills
in the appropriate fields and at the end of the data entry the user has the
option of printing their data entry. Once the user clicks Print the Word.dot
opens but the bookmarks I have in the .dot document does not populate with
the record results.

I get an error message: Object required.

Here is the code. Perhaps you might be able to tell me what is missing.

Sub PrintHazSurvRptWithWord(DataEntryForm)
Dim objWord As Word.Application

'Launch Word and load the HazardSurveillanceReport template
Set objWord = New Word.Application
objWord.Documents.Open "\\Sharedir\safety
database\Documents\HazardSurveillanceSurvey.dot"
objWord.ActiveDocument.FollowHyperlink "\\Sharedir\safety
database\Documents\HazardSurveillanceSurvey.dot"
objWord.Visible = True

'Add information using predefined bookmarks

With objWord.ActiveDocument.Bookmarks
.Item("Director").Range.Text = ReportPrintForm.Director
.Item("OverallTotal").Range.Text = ReportPrintForm.OverallTotal
.Item("STotal").Range.Text = ReportPrintForm.STotal
.Item("SCTotal").Range.Text = ReportPrintForm.SCTotal
.Item("HZTotal").Range.Text = ReportPrintForm.HZTotal
.Item("EMTotal").Range.Text = ReportPrintForm.EMTotal
.Item("FTotal").Range.Text = ReportPrintForm.FTotal
.Item("METotal").Range.Text = ReportPrintForm.METotal
.Item("UTotal").Range.Text = ReportPrintForm.UTotal
.Item("ICTotal").Range.Text = ReportPrintForm.ICTotal
.Item("CorrectiveActionDate").Range.Text =
ReportPrintForm.CorrectiveActionDate
.Item("S1").Range.Text = DataEntryForm.S1

I appreciate your help.

Kenny G
 
J

Jean-Guy Marcil

Kenny G was telling us:
Kenny G nous racontait que :
Hello,

Using Access 2002/Word 2002

I have an Access DB and a Word.dot letter. The user of the Access DB
fills in the appropriate fields and at the end of the data entry the
user has the option of printing their data entry. Once the user
clicks Print the Word.dot opens but the bookmarks I have in the .dot
document does not populate with the record results.

I get an error message: Object required.

Three things:

1) You are opening a template, not creating a document form a template.
2) Why don't you use a Document object instead of working with the
unreliable ActiveDocument?
3) You may want to check if Word is already running before creating a new
instance...

See my suggestions below:
Here is the code. Perhaps you might be able to tell me what is
missing.
Sub PrintHazSurvRptWithWord(DataEntryForm)
Dim objWord As Word.Application

Dim objDoc As Word.Document

'Launch Word and create a document from
'the HazardSurveillanceReport template
Set objWord = New Word.Application
objWord.Documents.Open "\\Sharedir\safety
database\Documents\HazardSurveillanceSurvey.dot"
objWord.ActiveDocument.FollowHyperlink "\\Sharedir\safety
database\Documents\HazardSurveillanceSurvey.dot"
(Why open template and then follow a hyperlink to the same template?)

objWord.Visible = True
Set objDoc =
objWord.Documents.Add("\\Sharedir\safetydatabase\Documents\HazardSurveillanceSurvey.dot")

'Add information using predefined bookmarks
With objDoc.Bookmarks
.Item("Director").Range.Text = ReportPrintForm.Director

etc.
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
K

Kenny G

Jean-Guy,

Thanks for your assistance. The errors you pointed out were corrected and
it works with no error message, but, my Bookmarks come up empty. I see the
"I" bar and when I open tools, bookmarks I see my bookmarks listed and I can
GoTo each one and the cursor moved to each bookmark. Is there possibly a
missing connection?

Thanks,
 
J

Jean-Guy Marcil

Kenny G was telling us:
Kenny G nous racontait que :
Jean-Guy,

Thanks for your assistance. The errors you pointed out were
corrected and it works with no error message, but, my Bookmarks come
up empty. I see the "I" bar and when I open tools, bookmarks I see
my bookmarks listed and I can GoTo each one and the cursor moved to
each bookmark. Is there possibly a missing connection?

Have you stepped through the code to make sure the values are being passed
from Access to Word?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
K

Kenny G

Jean-Guy,

No, I have never do anything like that before. Is this done through the
Visual Basic Editor?

Ken
 
J

Jean-Guy Marcil

Kenny G was telling us:
Kenny G nous racontait que :
Jean-Guy,

No, I have never do anything like that before. Is this done through
the Visual Basic Editor?

Yes. Place the cursor in the main procedure.
F5 will launch the whole procedure. If you have set break (or used STOP) the
execution will stop on those lines.
Also, F8 executes line by line. In View, display the Local window to see
what is going on with your variables.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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