S
snowiii
Jeanette:
I took your code and modified it (see below)...It keeps coming back with the
message "You must select a valid word document. No data imported." I made
sure there are two word docuemnts in the target directory...What could be
causing this to occur?
Thanks!
Snowiii
Private Sub GetWordData_Click()
Dim appWord As Word.Application
Dim doc As Word.Document
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim blnQuitWord As Boolean
Dim strPath As String
Dim strSourceFolder As String
Dim strFileName As String
On Error GoTo ErrorHandling
'hard code the path and folder where the word forms are stored
strPath = "x:\Tom Snow\Temp\"
strSourceFolder = strPath & "\"
strFileName = Dir(strSourceFolder)
Set appWord = GetObject(, "Word.Application")
Do While Left$(strFileName, 2) <> "xx"
strFileName = Dir(strSourceFolder)
If Left$(strFileName, 2) = "xx" Then
'don't process
Else
'Debug.Print strFileName
Set doc = appWord.Documents.Open(strFileName)
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=X:\Tom Snow\Coverage Verification Project\db folder\" & _
"Cart.mdb;"
rst.Open "Maintbl", cnn, _
adOpenKeyset, adLockOptimistic
With rst
.AddNew
!Requestor = doc.FormFields("Requestor").Result
!CvgType = doc.FormFields("CvgType").Result
!CAT = doc.FormFields("CAT").Result
!RequestDate = doc.FormFields("RequestDate").Result
!Handler = doc.FormFields("Handler").Result
!HandlerPhone = doc.FormFields("HandlerPhone").Result
!Office = doc.FormFields("Office").Result
!Policy = doc.FormFields("Policy").Result
!EventNo = doc.FormFields("EventNo").Result
!Insured = doc.FormFields("Insured").Result
!DOL = doc.FormFields("DOL").Result
!VehicleYear = doc.FormFields("VehicleYear").Result
!VehicleMake = doc.FormFields("VehicleMake").Result
!VehicleModel = doc.FormFields("VehicleModel").Result
!VIN = doc.FormFields("VIN").Result
!ApproximateReserve = doc.FormFields("ApproximateReserve").Result
!Address = doc.FormFields("Address").Result
!LossLoc = doc.FormFields("LossLoc").Result
!DescriptionOfLoss = doc.FormFields("DescriptionOfLoss").Result
!UnverifiedStatus = doc.FormFields("UnverifiedStatus").Result
!InsuredPhone = doc.FormFields("InsuredPhone").Result
!InsuredState = doc.FormFields("InsuredState").Result
!InsuredZip = doc.FormFields("InsuredZip").Result
!Schedule = doc.FormFields("Schedule").Result
!Bix = doc.FormFields("Bix").Result
!IneligibleStatus = doc.FormFields("IneligibleStatus").Result
!CancelledStatus = doc.FormFields("CancelledStatus").Result
!PayLapseStatus = doc.FormFields("PayLapseStatus").Result
!MicrofilmStatus = doc.FormFields("MicrofilmStatus").Result
!VNOP = doc.FormFields("VNOP").Result
!VehiclePurchasedDate = doc.FormFields("VehiclePurchasedDate").Result
!CustomerNotifyDate = doc.FormFields("CustomerNotifyDate").Result
!CopyOfPolicy = doc.FormFields("CopyofPolicy").Result
!CopyOfApplication = doc.FormFields("CopyofApplication").Result
!UnderwritingFile = doc.FormFields("UnderwritingFile").Result
!Comments = doc.FormFields("Comments").Result
!CopyAppComments = doc.FormFields("CopyAppComments").Result
!WritingCo = doc.FormFields("WritingCo").Result
.Update
.Close
End With
doc.Close
Name strSourceFolder & strFileName As strSourceFolder & "xx" & strFileName
End If
Loop
If blnQuitWord Then appWord.Quit
cnn.Close
MsgBox "INQUIRY 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
I took your code and modified it (see below)...It keeps coming back with the
message "You must select a valid word document. No data imported." I made
sure there are two word docuemnts in the target directory...What could be
causing this to occur?
Thanks!
Snowiii
Private Sub GetWordData_Click()
Dim appWord As Word.Application
Dim doc As Word.Document
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim blnQuitWord As Boolean
Dim strPath As String
Dim strSourceFolder As String
Dim strFileName As String
On Error GoTo ErrorHandling
'hard code the path and folder where the word forms are stored
strPath = "x:\Tom Snow\Temp\"
strSourceFolder = strPath & "\"
strFileName = Dir(strSourceFolder)
Set appWord = GetObject(, "Word.Application")
Do While Left$(strFileName, 2) <> "xx"
strFileName = Dir(strSourceFolder)
If Left$(strFileName, 2) = "xx" Then
'don't process
Else
'Debug.Print strFileName
Set doc = appWord.Documents.Open(strFileName)
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=X:\Tom Snow\Coverage Verification Project\db folder\" & _
"Cart.mdb;"
rst.Open "Maintbl", cnn, _
adOpenKeyset, adLockOptimistic
With rst
.AddNew
!Requestor = doc.FormFields("Requestor").Result
!CvgType = doc.FormFields("CvgType").Result
!CAT = doc.FormFields("CAT").Result
!RequestDate = doc.FormFields("RequestDate").Result
!Handler = doc.FormFields("Handler").Result
!HandlerPhone = doc.FormFields("HandlerPhone").Result
!Office = doc.FormFields("Office").Result
!Policy = doc.FormFields("Policy").Result
!EventNo = doc.FormFields("EventNo").Result
!Insured = doc.FormFields("Insured").Result
!DOL = doc.FormFields("DOL").Result
!VehicleYear = doc.FormFields("VehicleYear").Result
!VehicleMake = doc.FormFields("VehicleMake").Result
!VehicleModel = doc.FormFields("VehicleModel").Result
!VIN = doc.FormFields("VIN").Result
!ApproximateReserve = doc.FormFields("ApproximateReserve").Result
!Address = doc.FormFields("Address").Result
!LossLoc = doc.FormFields("LossLoc").Result
!DescriptionOfLoss = doc.FormFields("DescriptionOfLoss").Result
!UnverifiedStatus = doc.FormFields("UnverifiedStatus").Result
!InsuredPhone = doc.FormFields("InsuredPhone").Result
!InsuredState = doc.FormFields("InsuredState").Result
!InsuredZip = doc.FormFields("InsuredZip").Result
!Schedule = doc.FormFields("Schedule").Result
!Bix = doc.FormFields("Bix").Result
!IneligibleStatus = doc.FormFields("IneligibleStatus").Result
!CancelledStatus = doc.FormFields("CancelledStatus").Result
!PayLapseStatus = doc.FormFields("PayLapseStatus").Result
!MicrofilmStatus = doc.FormFields("MicrofilmStatus").Result
!VNOP = doc.FormFields("VNOP").Result
!VehiclePurchasedDate = doc.FormFields("VehiclePurchasedDate").Result
!CustomerNotifyDate = doc.FormFields("CustomerNotifyDate").Result
!CopyOfPolicy = doc.FormFields("CopyofPolicy").Result
!CopyOfApplication = doc.FormFields("CopyofApplication").Result
!UnderwritingFile = doc.FormFields("UnderwritingFile").Result
!Comments = doc.FormFields("Comments").Result
!CopyAppComments = doc.FormFields("CopyAppComments").Result
!WritingCo = doc.FormFields("WritingCo").Result
.Update
.Close
End With
doc.Close
Name strSourceFolder & strFileName As strSourceFolder & "xx" & strFileName
End If
Loop
If blnQuitWord Then appWord.Quit
cnn.Close
MsgBox "INQUIRY 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