Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automation Error - The Server Threw an Exception 1

Status
Not open for further replies.

pra

Instructor
Jun 12, 2001
6
US
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



 
Instead of:

Set appWord = GetObject(, "Word.Application")
Set doc = appWord.Documents.Open(strDocName)

Try:
Set doc = GetObject(strDocName, "Word.Application")

Hope that helps... Terry M. Hoey
th3856@txmail.sbc.com
While I don't mind e-mail messages, please post all questions in these forums for the benefit of all members.
 
The line you gave me fixed that error, now I am getting a
"432: File name or class name not found during automation operation"

UGH!

Any ideas? I tried typing the file name in the Input box, then i tried typing the path to the file, same error.
 
Please repost the new code. Also, I have never done this before, so please don't expect miracles... Terry M. Hoey
th3856@txmail.sbc.com
While I don't mind e-mail messages, please post all questions in these forums for the benefit of all members.
 
here is my updated code. It seems as if my code isn't finding my file or opening the word file. If I ' out the Input box, and strDocName, and enter the direct path under GetObject, I then get a "2147467259:Database has been placed in a state by user 'Admin' on machine 'PRA" that prevents it from being opened or locked" I figure this message is telling me to set the database as current database, since it has to be open to run the module.


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:\AATest\" & _
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)

Set doc = GetObject(strDocName, "Word.Application")

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 .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

Thanks!!!! Pam

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top