By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,480 Members | 771 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,480 IT Pros & Developers. It's quick & easy.

How to send the current record to Word 2000 with automation

P: n/a
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


P: n/a

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:
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 <snip> 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 #2

This discussion thread is closed

Replies have been disabled for this discussion.