Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2005

Tip: Looking for answers? Try searching our database.

Object required.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kenny G - 08 Apr 2005 17:33 GMT
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
Signature

Kenny G

Jean-Guy Marcil - 08 Apr 2005 18:00 GMT
Kenny G was telling us:
Kenny G nous racontait que :

> Hello,
>
[quoted text clipped - 7 lines]
>
> 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.
Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Kenny G - 08 Apr 2005 19:01 GMT
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,

> Kenny G was telling us:
> Kenny G nous racontait que :
[quoted text clipped - 48 lines]
>
> etc.
Jean-Guy Marcil - 09 Apr 2005 04:21 GMT
Kenny G was telling us:
Kenny G nous racontait que :

> Jean-Guy,
>
[quoted text clipped - 3 lines]
> 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?

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Kenny G - 11 Apr 2005 16:26 GMT
Jean-Guy,

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

Ken

> Kenny G was telling us:
> Kenny G nous racontait que :
[quoted text clipped - 9 lines]
> Have you stepped through the code to make sure the values are being passed
> from Access to Word?
Jean-Guy Marcil - 12 Apr 2005 02:49 GMT
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.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Kenny G - 12 Apr 2005 18:00 GMT
Jean_Guy,

Many thanks for your help.  This will help me a lot.

Kenny G

> Kenny G was telling us:
> Kenny G nous racontait que :
[quoted text clipped - 9 lines]
> Also, F8 executes line by line. In View, display the Local window to see
> what is going on with your variables.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.