This module is taking data from a Word Form, and importing it into an Access Table.
When I run this Module I get the dialog box to type in the Word Document Name, enter the doc name, then I click OK. This is when I get the "Automation Error - The Server Threw an Exception" dialog box. Can you please help me figure out where my problem may be.
Thank You Very Much! Pam
Here is my code:
Sub WordDataImport()
Dim appWord As Word.Application
Dim doc As Word.Document
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strDocName As String
Dim blnQuitWord As Boolean
On Error GoTo ErrorHandling
strDocName = "C:\AAA-Test\" & _
InputBox("Enter the name of the Word contract " & _
"you want to import:", "Import Contract"
Set appWord = GetObject(, "Word.Application"
Set doc = appWord.Documents.Open(strDocName)
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=G:\MIS\PRA\Warranty\" & _
"Certification Plus Warranty 2001 converted.mdb;"
rst.Open "tblWarrantyLog", cnn, _
adOpenKeyset, adLockOptimistic
With rst
.AddNew
!ProjectName = doc.FormFields("fldProjectName".Result
!ProjectAddress = doc.FormFields("fldProjectAddress".Result
!ProjectCity = doc.FormFields("fldProject City".Result
.Update
.Close
End With
doc.Close
If blnQuitWord Then appWord.Quit
cnn.Close
MsgBox "Contract Imported!"
Cleanup:
Set rst = Nothing
Set cnn = Nothing
Set doc = Nothing
Set appWord = Nothing
Exit Sub
ErrorHandling:
Select Case Err
Case -2147022986, 429
Set appWord = CreateObject("Word.Application"
blnQuitWord = True
Resume Next
Case 5121, 5174
MsgBox "You must select a valid Word document. " _
& "No data imported.", vbOKOnly, _
"Document Not Found"
Case 5941
MsgBox "The document you selected does not " _
& "contain the required form fields. " _
& "No data imported.", vbOKOnly, _
"Fields Not Found"
Case Else
MsgBox Err & ": " & Err.Description
End Select
GoTo Cleanup
End Sub
When I run this Module I get the dialog box to type in the Word Document Name, enter the doc name, then I click OK. This is when I get the "Automation Error - The Server Threw an Exception" dialog box. Can you please help me figure out where my problem may be.
Thank You Very Much! Pam
Here is my code:
Sub WordDataImport()
Dim appWord As Word.Application
Dim doc As Word.Document
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strDocName As String
Dim blnQuitWord As Boolean
On Error GoTo ErrorHandling
strDocName = "C:\AAA-Test\" & _
InputBox("Enter the name of the Word contract " & _
"you want to import:", "Import Contract"
Set appWord = GetObject(, "Word.Application"
Set doc = appWord.Documents.Open(strDocName)
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=G:\MIS\PRA\Warranty\" & _
"Certification Plus Warranty 2001 converted.mdb;"
rst.Open "tblWarrantyLog", cnn, _
adOpenKeyset, adLockOptimistic
With rst
.AddNew
!ProjectName = doc.FormFields("fldProjectName".Result
!ProjectAddress = doc.FormFields("fldProjectAddress".Result
!ProjectCity = doc.FormFields("fldProject City".Result
.Update
.Close
End With
doc.Close
If blnQuitWord Then appWord.Quit
cnn.Close
MsgBox "Contract Imported!"
Cleanup:
Set rst = Nothing
Set cnn = Nothing
Set doc = Nothing
Set appWord = Nothing
Exit Sub
ErrorHandling:
Select Case Err
Case -2147022986, 429
Set appWord = CreateObject("Word.Application"
blnQuitWord = True
Resume Next
Case 5121, 5174
MsgBox "You must select a valid Word document. " _
& "No data imported.", vbOKOnly, _
"Document Not Found"
Case 5941
MsgBox "The document you selected does not " _
& "contain the required form fields. " _
& "No data imported.", vbOKOnly, _
"Fields Not Found"
Case Else
MsgBox Err & ": " & Err.Description
End Select
GoTo Cleanup
End Sub