Launch Word, store text in Access

  • Thread starter Thread starter Victor Boris Arnold
  • Start date Start date
V

Victor Boris Arnold

I'd like to be able to launch Microsoft Word from an
Access form, have the user type a small document therein,
and store the typed text in an Access table (at which time
Word would be closed). The Word document itself does not
have to be stored as a separate file. Can anyone think of
a way to do this?
 
You could write a macro in word that executes when the word document is
closed and stores the document into your access database.
 
Could you provide a little more detail on what you
envision? Keep in mind that Word would be launched from an
activity in Access (probably via a form). If the Access
table in question is open, would the Word macro be
prevented from updating it?
 
Victor,

I have not done this personally, but envision the following sequence of
events

(1) User launches word from a button on your form
(1a) A macro that is stored in the users template directory initializes
a class (from the AutoExec Macro)
(1b) This macro monitors the application event DocumentBeforeClose
(2) User edits document
(3) User and closes saves document
(3a) DocumentBeforeClose event is fired
(4) Open a connection to the database
(4a) store the text of the document into the respective table
(4b) close the connection
(5) Finished.

Alternatively you can also monitor the event in your access form for
instance:

Dim WithEvents app As Word.Application

Private Sub app_DocumentBeforeClose(ByVal Doc As Word.Document, Cancel As
Boolean)
Debug.Print Doc.Path
Stop
End Sub

Private Sub Form_Load()
Set app = New Word.Application
app.Visible = True
End Sub

Regards,
Dan
 
What does the "Debug.Print" statement do? I don't see a
Debug keyword in my Access 2000 help. Does this statement
open a VBA debug window? Does it pass the path (in this
case) back to Access?
 
Victor,

Debug.Print prints to the immediate window. It sounds like you will need to
research the Word Object model, which can be found in the word help index
under Programming Information.
 
I'm getting closer...

If I define a field as an object, then in datasheet view I
can open the Insert menu, select Object, then select
Microsoft Word Document, Word will launch. I can then type
my document. After that, open Word's File menu, and the
Close item has been altered to include a phrase about
returning to my Access table. If I select that, Word
closes and stores the document text in my table field.

Now, there are two things I'd like to do:
1. Do the Insert Object thing programatically, and not
have to have the user go through the whole menu process.
2. Use a specific Word template when I launch Word.
 
create a new table, with an OLEobject field

create a new form
on the form "Insert" an "Object" of type Word Document.

bind the control you just created to the field you just created.

(david)
 
I'd like to be able to launch Microsoft Word from an
Access form, have the user type a small document therein,
and store the typed text in an Access table (at which time
Word would be closed). The Word document itself does not
have to be stored as a separate file. Can anyone think of
a way to do this?

I would do the whole thing in Word, and not use Access at all (except
perhaps to create the tables and queries in the first place). Using DAO or
ADO to access the data is the same in both applications,

Set strSQL = "INSERT INTO MyTable (IDNumber, Text) " & _
"(" & dwGetNextIDNumber() & ", " & _
"""" & ActiveWindow.Selection.Range.Text & """)"

db.Execute strSQL, dbFailOnError

If Err.Number <> 0 Then
' etc etc....


The only difference is that Access gives you a ready made CurrentDB() or
CurrentProject(), while in Word you have to use two lines to create the
database or connection.

OLE automation is a terrific device when there is no alternative, but if
there is another method, then grab it with both hands!!

Hope that helps


Tim F
 
Back
Top