Adding text to a Word file from inside Access - Mr Tangard!

P

pvp

You were very helpful last time so I thought I'd run to
you with this one...

I am in an Access form and I doubleclick on a bound OLE
object which is a Word file. this will open the file and
I can then faff around inside it, etc... and save it. All
OK.

Goody! I hear you cry. But...

I want to open this Word file (before the double-click
takes effect and presents the file in the Word
application 'thorugh' Access) and stick some text in it,
then save this text. Then the file would open as usual in
the Word aplication with newly added text I programmed.
How would you do this?

I tried to open the file as a Word doc and as a Word app
and both end up failing:

"
'Dim docApp As Word.Application
'Dim docDoc As Word.Document

'Set docApp = GetObject("C:\counselog docs\" &
Me.Text51 & ".doc", "Word.Application")
'Set docDoc = GetObject("C:\counselog docs\" &
Me.Text51 & ".doc")
'Set docDoc = docApp.Documents.Add
'docApp.selection.typetext "__________________________
_" & vbCrLf
'docApp.selection.typetext "General Comment:" & vbCrLf
'docDoc.Close wdSaveChanges
'Set docApp = Nothing
"
(It's all commented out but I have tried most
combinations and failed!)

Waiting with bated breath.

Thanks.
 
D

Doug Robbins - Word MVP

Hi Peter,

Use something like

Option Compare Database
Option Explicit
Dim WordApp As Object
Dim WordDoc As Object

Private Sub CmdName_Click()

On Error GoTo CreateWordApp
Set WordApp = GetObject(, "Word.Application")
On Error GoTo 0
Set WordDoc = WordApp.Documents.Open("C:\counselog docs\" & Me.Text51 &
".doc")
WordDoc.Selection.TypeText "General Comment:" & vbCrLf
WordDoc.Save
WordDoc.Close ' Access will not recognise wdSaveChanges in
WordDoc.Close wdSaveChanges

CreateWordApp:

Set WordApp = CreateObject("Word.Application")
Resume Next

End Sub

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
M

Mark Tangard

Sorry, my knowledge of Access is about equivalent to my
mother's comprehension of VBA (don't ask), and my grasp
of automating one program from another is only slightly
better.

This illustrates one reason why I think it's foolish and
a little offensive to see an MVP's name in the subject
line of a post. It implies, at least midly, that you'd
rather not hear from anyone else, although probably a
majority of the others could help you. Some may assume,
since the post isn't directed to them, that there'd be
no point even bothering to read it.

It also implies we're essentially lounging around waiting
to be summoned for any question you have, regardless of
topic. The reality is, as unpaid and often unthanked
volunteers, we have the right to choose what to answer
(based not only on the topic but also on other things
such as how clearly the query is phrased).
 
P

pvp

Mark,

I apologise if I offended you with my ignorance of this
aspect of etiquette. I had seen others do it. You were
very helpful to me last time and so I regarded you as a
good source of knowledge this time round. It was a
recogntion of your talent and not taking you for
granted! (8v>)>

I hope your mother is well and that you do not have to
spend too much time lounging around waiting to be
summoned by the likes of me...

Doug Robbins actually helped me out this time.

Regards,
pvp
 

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