Amanda:
You would not insert the data directly into an Access form but into a table
on which a form can be based. Each Word document would be one row in the
table, so you could then analyze the data in Access. First you should create
a reference in your Access databse to the Microsoft Word Object Library which
you do by selecting Tools|References on the VBA menu bar while in your Access
database. In the dialogue scroll down until you find the reference then
check it.
To add the data to the table you can create a procedure in a standard module
in the databse. The following procedure illustrates a very simple example
where data from a Word document with two form fields is inserted into a table
called MyContacts with columns FirstName and LastName:
Sub GetWordForm(strPath As String)
On Error GoTo Err_Handler
Dim objWord As Object
Dim objDoc As Object
Dim fld As Word.FormField
Dim cmd As ADODB.Command
Dim frm As Form
Dim strSQL As String
Dim strValueList As String
' if Word open return reference to it
' else establish reference to it
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number = 429 Then
Set objWord = CreateObject("Word.Application")
End If
AppActivate "Microsoft Word"
On Error GoTo Err_Handler
Set objDoc = objWord.Documents.Open(strPath)
' loop through form fields in document and build value list
For Each fld In objDoc.FormFields
strValueList = strValueList & ",""" & fld.Result & """"
Next fld
' remove leading comma
strValueList = Mid(strValueList, 2)
' insert row into table
strSQL = "INSERT INTO MyContacts(FirstName,LastName)" & _
"VALUES(" & strValueList & ")"
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText
cmd.CommandText = strSQL
cmd.Execute
objDoc.Close
Set objDoc = Nothing
Set objWord = Nothing
Exit_here:
On Error GoTo 0
Exit Sub
Err_Handler:
MsgBox Err.Description & " (" & Err.Number & ")"
Resume Exit_here
End Sub
You'd call it by passing the path to the Word document to the procedure, e.g.
GetWordForm "F:\SomeFolder\SomeSubFolder\SomeDocument.doc"
You could do this in the Click event procedure of a button on a form say.
If you do it with a buton on a form bound to the table you can add the
following line to the procedure before the Exit Here: label:
Me.Requery
This would requery the form so it includes the new record in its underlying
recordset.
You would not hard-code the path of course in reality, but get it from
somewhere as a variable. Opening a common dialog to browse to the file would
be the obvious solution. I use Bill Wilson's freely available
BrowseForFileClass class module, which can be downloaded from:
http://community.netscape.com/n/pfx...yMessages&tsn=1&tid=22415&webtag=ws-msdevapps
Ken Sheridan
Stafford, England