Newsgroup: it.comp.appl.access
Titolo: Mandare dei record in un documento di word

Ciao a tutti. Ho questo problema: mi sono costruito un piccolo database che
gestisce i clienti, i fornitori, gli ordini ecc.
Vorrei che quando inserisco un ordine ci sia un sistema per aprire un
documento di word e che in automatico sul documento venga scritto il nome
del cliente, l'indirizzo, il numero dell'ordine, ...
Avete idea di come si faccia o di dove possa trovare notizie al riguardo? Io
non sono un programmatore quindo se ci fosse un sistema per farlo senza
dover scrivere del codice sarebbe meglio.
Ciao, Luca

 wrote in message
8tmu3l$qm5$1...@fe1.cs.interbusiness.it...

Studiati il Mail Merge del word , vedrai che è molto semplice se non vuoi
fare cose super-automatizzate.
Ciao Bobbit

 fare cose super-automatizzate.
Ci avevo pensato, ma la mia esigenza è di avere un pulsante in access che mi
permetta di fare questo sul record attivo.

 wrote in message
8tni77$5u2$1...@stargate1.inet.it...

Lo puoi fare.... leggiti questo
ACC: Sending the Current Record to Word 97 with Automation
----------------------------------------------------------------------------
----
The information in this article applies to:
Microsoft Access versions 7.0, 97
Microsoft Word 97
----------------------------------------------------------------------------
----
SUMMARY
Advanced: Requires expert coding, interoperability, and multiuser skills.
This article shows you how to merge the current record in a Microsoft Access
7.0 and 97 object into a Microsoft Word 97 document, print it, and then
close Microsoft Word 97.
This article assumes that you are familiar with Visual Basic for
Applications and with creating Microsoft Access applications using the
programming tools provided with Microsoft Access. For more information about
Visual Basic for Applications, please refer to your version of the "Building
Applications with Microsoft Access" manual.
MORE INFORMATION
Microsoft Word 97 uses the Visual Basic for Applications programming model
instead of the WordBasic flat command model used in earlier versions.
For information about how to send the current record to Microsoft Word
version 7.0 or earlier using WordBasic, please see the following article in
the Microsoft Knowledge Base:
Q124862 ACC: Sending the Current Record to Word with OLE Automation
The following example uses bookmarks in a Microsoft Word 97 document to mark
the locations where you want to place data from a record on a Microsoft
Access form.
Creating a Microsoft Word 97 Document
Start Microsoft Word 97 and create the following new document:
First Last
Address
City, Region, PostalCode
Dear Greeting,
Northwind Traders would like to thank you for
your employment during the past year. Below
you will find your photo. If this is not your
most current picture, please let us know.
Photo
Sincerely,
Northwind Traders
Create a bookmark in Microsoft Word 97 for the words "First," "Last,"
"Address," "City," "Region," "PostalCode," "Greeting," and "Photo":
Select the word "First."
On the Insert menu, click Bookmark.
In the Bookmark Name box, type "First," (without the quotation marks) and
then click Add.
Repeat steps 2a through 2c for each of the remaining words, substituting
that word for the word "First" in steps 2a and 2c.
Save the document as C:\My Documents\MyMerge.doc, and then quit Microsoft
Word 97.
Sending Data to Microsoft Word from a Microsoft Access Form
Start Microsoft Access and open the sample database Northwind.mdb.
Set a reference to the Microsoft Word 8.0 Object Library. To do so, follow
these steps:
Open any module in Design view.
On the Tools menu, click References.
Click Microsoft Word 8.0 Object Library in the Available References box. If
that selection does not appear, browse for Msword8.olb, which installs by
default in the C:\Program Files\Microsoft Office\Office folder.
Click OK.
Close the module.
Open the Employees form in Design view.
Add a command button to the form and set the following properties:
   Command Button:
      Name: MergeButton
      Caption: Send to Word
      OnClick: [Event Procedure]
Set the OnClick property of the command button to the following event
procedure.
NOTE: In the following sample code, you must remove the comment from one
line of code as indicated, depending on your version of Microsoft Access.
      Private Sub MergeButton_Click()
      On Error GoTo MergeButton_Err
         Dim objWord As Word.Application
         ' Copy the Photo control on the Employees form.
         DoCmd.GoToControl "Photo"
         ' Remove the following comment in Microsoft Access 97.
         ' DoCmd.RunCommand acCmdCopy
         ' Remove the following comment in Microsoft Access 7.0.
         ' DoCmd.DoMenuItem acFormBar, acEditMenu, acCopy, , acMenuVer70
         ' Start Microsoft Word 97.
         Set objWord = CreateObject("Word.Application")
         With objWord
            ' Make the application visible.
            .Visible = True
            ' Open the document.
            .Documents.Open ("c:\my documents\mymerge.doc")
            ' Move to each bookmark and insert text from the form.
            .ActiveDocument.Bookmarks("First").Select
            .Selection.Text = (CStr(Forms!Employees!FirstName))
            .ActiveDocument.Bookmarks("Last").Select
            .Selection.Text = (CStr(Forms!Employees!LastName))
            .ActiveDocument.Bookmarks("Address").Select
            .Selection.Text = (CStr(Forms!Employees!Address))
            .ActiveDocument.Bookmarks("City").Select
            .Selection.Text = (CStr(Forms!Employees!City))
            .ActiveDocument.Bookmarks("Region").Select
            .Selection.Text = (CStr(Forms!Employees!Region))
            .ActiveDocument.Bookmarks("PostalCode").Select
            .Selection.Text = (CStr(Forms!Employees!PostalCode))
            .ActiveDocument.Bookmarks("Greeting").Select
            .Selection.Text = (CStr(Forms!Employees!FirstName))
            ' Paste the photo.
            .ActiveDocument.Bookmarks("Photo").Select
            .Selection.Paste
         End With
         ' Print the document in the foreground so Microsoft Word 97
         ' will not close until the document finishes printing.
         objWord.ActiveDocument.PrintOut Background:=False
         ' Close the document without saving changes.
         objWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
         ' Quit Microsoft Word 97 and release the object variable.
         objWord.Quit
         Set objWord = Nothing
         Exit Sub
      MergeButton_Err:
         ' If a field on the form is empty
         ' remove the bookmark text and continue.
         If Err.Number = 94 Then
            objWord.Selection.Text = ""
            Resume Next
         ' If the Photo field is empty.
         ElseIf Err.Number = 2046 Then
            MsgBox "Please add a photo to this record and try again."
         Else
            MsgBox Err.Number & vbCr & Err.Description
         End If
         Exit Sub
      End Sub
Save the Employees form and open it in Form view.
Click the Send To Word button to start Microsoft Word 97, merge data from
the current record on the form into MyMerge.doc, print the document, and
then close Microsoft Word 97.
NOTE: When you use this method of inserting text into a Word Document, you
are deleting the bookmark when you insert the record field content. If you
need to reference the text that you entered into the document, you must
bookmark it. You can use the following sample to add the bookmark "Last" to
the text inserted from record field "LastName."
  .ActiveDocument.Bookmarks("Last").Select
  .Selection.Text = (CStr(Forms!Employees!LastName))
  'add this line to reapply the bookmark name to the selection
  .ActiveDocument.Bookmarks.Add Name:="Last",Range:=Selection.Range
This macro could be used to simulate a mailmerge with Word that includes the
picture field from an Access record, by placing the above code in a
"For...Next", While...Wend, or "For...Each" Loop.
REFERENCES
For additional information about Automation theory and multiple examples on
automating all the Office 97 products, click the article number below to
view the article in the Microsoft Knowledge Base:
Q167223 OFF97: Microsoft Office 97 Automation Help File Available
For additional information about Automation between Microsoft Access 97 and
Microsoft Word, search the Help Index for "sharing data between
applications, Microsoft Word mail merge data."
For additional information about Automation between Microsoft Access 7.0 and
Microsoft Word, search the Help Index for "Word (Microsoft), sharing data."
For additional information about bookmarks, search the Microsoft Word 97
Help Index for "bookmarks," or ask the Microsoft Word 97 Office Assistant.
Additional query words:
Keywords : kbmacro kbole kbprg OffVBA word8 IntpOlea word95 vbappcode vbe
kbofficeprog
Version : WINDOWS:7.0,97
Platform : WINDOWS
Issue type : kbhowto
Technology :
Last Reviewed: May 10, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.
Article ID: Q131583
Last Reviewed:
May 10, 2000
Provided by Microsoft Product Support Services.
Ciao, Bobbit