run msgbox code in Word from Access

  • Thread starter Thread starter Todd
  • Start date Start date
T

Todd

I think I have a simple coding problem. I have code that creates a Word
document and populates it with info from my Access database. When it is
done, I want Word, not Access, to display a short message. If I just put in
a line that says...

MsgBox ("Hello world")

the message shows up in Access, not Word. Sorry if this is a silly
question. Thanks!

Todd
 
And why not do this from Word. That's what you want and that is what makes it
possible. A messagebox is modal dialog and will not pop up in word before you
are done in Access. I presume you have Word open and active while you are
creating your document. Why not implement something like:

with activedocument
msgbox "Hello World"
end with

where word is being called upon as an object so the call for the active
document should be to that object.

hth
 
I guess that is where I'm having trouble. I don't know quite where or how
to put in that code. Here is what I'm using...

Dim objWord As Word.Application
Dim docname As String

Set objWord = CreateObject("Word.Application")
With objWord
.Documents.Add "t:\dbase\templates\IPS\Main IPS.dotm"
.ActiveDocument.SaveAs FileName:=docname
.Visible = True
End With

I tried adding this after the .visile=true line:
..msgbox "Hello World"

This gave me a syntax error. Then, I tried just msgbox "Hello World" This
came up in Access, not Word.

I tried using your code after the .Visible=true line and the message came up
in Access.

Todd
 
Todd,

My guess is that Access still has focus. Try setting the focus to Word, by
that I mean that the application Word has to have focus. I don't recall
exactly but try setting something like with application setfocus (I used the
heplfile on this one that time..)
 
I can't seem to figure out how to set the focus to do such a thing. Anyone
out there know how to do this? Thanks!!!
 
Back
Top