Private Sub Command0_Click()
Dim app As Word.Application
Dim objDoc As Word.Document
Dim sVal As String
Set app = New Word.Application
Set objDoc = app.Documents.Open("C:\Documents and Settings\JKirley\Desktop\Corrective Action Report.doc")
sVal = objDoc.Content
On Error GoTo Err_CmdButton_Click
directory = "C:\Documents and Settings\JKirley\Desktop\Corrective Action Report"
If strFile = "" Then Exit Sub
Exit_CmdButton_Click:
Exit Sub
Err_CmdButton_Click:
MsgBox Err.Description
Resume Exit_CmdButton_Click
End Sub
On Error GoTo ErrorHandling
strDocName = "C:\Audit Results\" & _
InputBox("Enter the Audit report number" & _
"you want to import:", "Import Corrective Action Report*")
Set appWord = GetObject(, "Word.Application")
Set doc = appWord.Documents.Open(strDocName)
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\CA database_Backup\" & _
"Audit results.mdb;"
rst.Open "tblAuditResults", cnn, _
adOpenKeyset, adLockOptimistic
With rst
.AddNew
...blah blah blah, field field field...
.Update
.Close
End With
doc.Close
If blnQuitWord Then appWord.Quit
cnn.Close
MsgBox "Corrective Action Report 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