363,927 Members | 2749 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

How to send the current record to Word 2000 with automation

moelleni
P: n/a
moelleni
Hi,
I made an Access 2002 Database and wanted to automate it to sent the
current record to Word 2002. So readed the article "How to send the
current record to Word 2000 with automation" I tried to do this with my
db.
Here is my code:

Private Sub MergeButton_Click()
On Error GoTo MergeButton_Err

Dim objWord As Word.Application



'Start Microsoft Word 97.
Set objWord = CreateObject("Word.Application")

With objWord
'Make the application visible.
.Visible = True

'Open the document.
.Documents.Open ("D:\Aullo\Réclamation_Test.doc")

'Move to each bookmark and insert text from the form.

.ActiveDocument.Bookmarks("Matricule_E").Select
.Selection.Text = (CStr(Forms!Réclmation!Matricule_E))
.ActiveDocument.Bookmarks("Matricule_D").Select
.Selection.Text = (CStr(Forms!Réclamation!Matricule_D))



End With

'Print the document in the foreground so Microsoft Word 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 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


End If

Exit Sub
End Sub

Here is now my problem: It opens my word document but does not insert
any objets. I don't understand why??
Can anybody help my?

Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


Chuck Grimsby
P: n/a
Chuck Grimsby

The code you posted is fairly common, bases on (or perhaps exactly) the
code from the Access 97 Developer's Handbook
(http://www.developershandbook.com/) even if you didn't get it from
there.

The code does not actually "fill out" a word form, what it does is
_replace_ the form's bookmarks with the text from your application.

This means the code will fail if either your form doesn't have
bookmarks in it (most likely case) or you're using it to fill out a
previously filled out form.

moelleni wrote:[color=blue]
> Hi,
> I made an Access 2002 Database and wanted to automate it to sent the
> current record to Word 2002. So readed the article "How to send the
> current record to Word 2000 with automation" I tried to do this with my
> db.
> Here is my code:
>
> Private Sub MergeButton_Click()
> On Error GoTo MergeButton_Err
> Dim objWord As Word.Application
> 'Start Microsoft Word 97.
> Set objWord = CreateObject("Word.Application")
> With objWord
> 'Make the application visible.
> .Visible = True
> 'Open the document.
> .Documents.Open ("D:\Aullo\Réclamation_Test.doc")
> 'Move to each bookmark and insert text from the form.
> .ActiveDocument.Bookmarks("Matricule_E").Select
> .Selection.Text = (CStr(Forms!Réclmation!Matricule_E))
> .ActiveDocument.Bookmarks("Matricule_D").Select
> .Selection.Text = (CStr(Forms!Réclamation!Matricule_D))
> End With[/color]
<snip>[color=blue]
> Here is now my problem: It opens my word document but does not insert
> any objets. I don't understand why??
> Can anybody help my?[/color]

Nov 13 '05 #2

Post your reply

Help answer this question



Didn't find the answer to your Microsoft Access / VBA question?

You can also browse similar questions: Microsoft Access / VBA