Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Importing / Linking / September 2005

Tip: Looking for answers? Try searching our database.

Sending data from Access to Word

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Helen - 11 Sep 2005 05:08 GMT
I need to send certain data from an open form in Access to Word. I need Word
to open a new document based on a custom template, and insert the proper
information at bookmarked fields. The user will then email the Word document
back and forth with other users for additional data. Using the following
code, the debugger stops me on line 2 and says the user defined function is
not recognized. I'm lost, I'm severely VBA challenged, and I have just two
days to get this running before I go out for surgery. Any help would be
appreciated. Alternatively, send alcohol...

Thanks!

Public Sub PrintToWord()
Dim wd As Word.Application
Dim myDoc As Word.Document

Set wd = New Word.Application
wd.Documents.Add “J:\Forms Designers\Conversions and updates\Forms HC-HD\2
Draft\HD AppointmentDB.dot”  ' The name and path
Set myDoc = wd.ActiveDocument
With wd.Selection
           .GoTo wdGoToBookmark, Name:=”Client” ' The name of the bookmark
           ‘.Font.Bold = True  ' You can choose if bold
           ‘.Font.Underline = False  ' or underline
           .TypeText Text:=me.ClientID ' insert values in field
   End With
   wd.Visible = True

Signature

Helen

John Nurick - 11 Sep 2005 07:41 GMT
Hi Helen,

It's usually better to avoid using the Selection object when automating
Word. Try something like

 Set wd = New Word.Application
 Set myDoc = wd.Documents.Add "blah blah.dot"

 With MyDoc.Bookmarks
     myDoc.Bookmarks("Client").Range.Text = Me.ClientID.Value
   ...

 End With

 myDoc.Save   

Also, remember that if you replace the text of a bookmark, either as
above or by selecting it and using TypeText, you destroy the bookmark.
There are techniques for saving the location of the bookmark first and
re-creating it later. An alternative is to use formfields where you want
to put the data: these are more permanent.

For more on Word, see http://word.mvps.org

>I need to send certain data from an open form in Access to Word. I need Word
>to open a new document based on a custom template, and insert the proper
[quoted text clipped - 22 lines]
>    End With
>    wd.Visible = True

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
Douglas J. Steele - 11 Sep 2005 12:28 GMT
It looks as though you haven't set a reference to Word in your Access
application.

With any code module open, select Tools | References from the menu bar.
Scroll through the list of available references until you find the one for
Word (It'll be something like "Microsoft Word x.0 Object Library") and
select it.

Alternatively, change your code from the Early Binding you're currently
using to Late Binding:

Public Sub PrintToWord()
Dim wd As Object
Dim myDoc As Object

Set wd = CreateObject("Word.Application")
wd.Documents.Add "J:\Forms Designers\Conversions and updates\Forms HC-HD\2
Draft\HD AppointmentDB.dot"  ' The name and path
Set myDoc = wd.ActiveDocument
With wd.Selection
           .GoTo wdGoToBookmark, Name:="Client" ' The name of the bookmark
           '.Font.Bold = True  ' You can choose if bold
           '.Font.Underline = False  ' or underline
           .TypeText Text:=me.ClientID ' insert values in field
   End With
   wd.Visible = True

The latter approach is better if your application is going to be used by
multiple users, and you're not sure which version of Word they'll have
installed.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

>I need to send certain data from an open form in Access to Word. I need
>Word
[quoted text clipped - 25 lines]
>    End With
>    wd.Visible = True
Helen - 12 Sep 2005 17:52 GMT
Thanks, Doug and John. I'll try these and see if I can get it working. I'm
just so lost with even VBA basics. :-)
Signature

Helen

> It looks as though you haven't set a reference to Word in your Access
> application.
[quoted text clipped - 56 lines]
> >    End With
> >    wd.Visible = True
 
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.