What have i done wrong

E

Emma Hope

Hi All,

I want to be able to add some fields from my Access database in a Word
document. For example a very very simplified version of my Word document is

Dear AAA

Your monthly submission is BBB.

Something else, something else CCC.

effectively i want my user to press a button on an Access form and it to do
everything for them. So far i have googled and created the following:

Private Sub Command0_Click()
Dim strTemplateFile As String
Dim objWord As Object: Dim objWordDoc As Object
Set rsEmployee = CurrentDb.OpenRecordset("tblFileShortfallAnalysis")
Set objWord = CreateObject("Word.Application"): objWord.Visible = True
strTemplateFile = CurrentProject.Path & "\Introduction.doc"
Set objWordDoc = objWord.Documents.ADD
With objWordDoc
.Content.InsertFile strTemplateFile
.Content.InsertBefore & rsEmployee![Person Name] & vbCrLf & vbCrLf
.SaveAs FileName:=CurrentProject.Path & "\" & rsEmployee![Person Name]
& ".doc"
End With
End Sub

i only seem to be able to insert text at the top or the bottom, what i want
is to be able to save, move down one line, move right five characters, insert
AAA, then move down two lines and move right 27 characters, insert BBB etc.

I thought .selection.movedown Unit:=wdLine, Count:=2 etc would work but each
time i am told 'run time error 438, object doesn't support this property or
method'

Please can someone help me out and tell me what i'm doing wrong!

Thanks
Emma
 
E

Emma Hope

Thanks for the suggestions but i can't use them for the following reasons, i
really need an answer to my question:

The report is far too long to use an Access report.

The mail merge option can't be used as the user will install this database
on their own PC at any location they wish and so the Word document won't be
able to find the source data.

i also belive 'bookmarks' could be an option but are not in this case for
the same reason as above.

If anyone can help me with my question, i'd be grateful.

Thanks
 
R

Rick Brandt

Emma said:
Thanks for the suggestions but i can't use them for the following
reasons, i really need an answer to my question:

The report is far too long to use an Access report.

How many thousands of pages is it?
The mail merge option can't be used as the user will install this
database on their own PC at any location they wish and so the Word
document won't be able to find the source data.

Code in your app can create the Word template so location is not an issue.
 
P

Pete

Well in that case, you probally need to post in microsoft.public.word.vba as
building a document from VBA is not something an MS Access guy will attempt
very often. Good Luck,

Pete D.
 
E

Emma Hope

Hi Rick,

Not quite thousands but around 20 to 50. 90% of the document is going to be
the same in every case, i.e. template but the remaining 10% is personalised
to the user, i.e. name and figures specific to them.

Could you point me in the right direction regarding the second part of your
answer?

Thanks
Emma
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top