I have an MS Access database that I automated to import an MS Word document into the database. When I look at a Report or Form I see weird characters that should be line feeds (the square boxes). Is there any way to correct this?
Any help would be greatly appreciated.
I am using the following code:
Any help would be greatly appreciated.
I am using the following code:
Code:
Public Sub GetWordData()
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
Dim strpath As String
Dim strfile As String
Dim strfilename As String
strpath = "C:\Testfolder\"
strfile = Dir("strpath & *.doc")
strfilename = strpath & strfile
On Error GoTo ErrorHandling
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Testfolder\Customfeed.mdb;"
rst.Open "tblfeedbck", cnn, _
adOpenKeyset, adLockOptimistic
' Outer WHILE
strfile = Dir(strfilename)
Do While strfile <> ""
If strfile <> "." And strfile <> ".." Then
strDocName = strpath & strfile
Set appWord = GetObject(, "Word.Application")
blnQuitWord = True
Set doc = appWord.Documents.Open(strDocName)
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect
End If
With rst
.AddNew
!FRN = doc.FormFields("txtFRN").Result
If (IsNull(doc.FormFields("dteSessionDate").Result)) Then
!SessionDate = ""
Else
!SessionDate = doc.FormFields("dteSessionDate").Result
End If
If (IsNull(doc.FormFields("Dropdown1").Result)) Then
!BranchName = ""
Else
!BranchName = doc.FormFields("Dropdown1").Result
End If
If (IsNull(doc.FormFields("Dropdown2").Result)) Then
!ITName = ""
Else
!ITName = doc.FormFields("Dropdown2").Result
End If
If (IsNull(doc.FormFields("txtITLeadName").Result)) Then
!ITLeadName = ""
Else
!ITLeadName = doc.FormFields("txtITLeadName").Result
End If
If (IsNull(doc.FormFields("txtITLExt").Result)) Then
!ITLExt = ""
Else
!ITLExt = doc.FormFields("txtITLExt").Result
End If
If (IsNull(doc.FormFields("txtFSFName").Result)) Then
!FSFName = ""
Else
!FSFName = doc.FormFields("txtFSFName").Result
End If
If (IsNull(doc.FormFields("txtFSFExt").Result)) Then
!FSFExt = ""
Else
!FSFExt = doc.FormFields("txtFSFExt").Result
End If
If (IsNull(doc.FormFields("intNoAttendees").Result)) Then
!NoAttendees = "00"
Else
!NoAttendees = doc.FormFields("intNoAttendees").Result
End If
If (IsNull(doc.FormFields("frmcombo").Result)) Then
!PGSecNo = ""
Else
!PGSecNo = doc.FormFields("frmcombo").Result
End If
If (IsNull(doc.FormFields("Dropdown4").Result)) Then
!FBSource = ""
Else
!FBSource = doc.FormFields("Dropdown4").Result
End If
If (IsNull(doc.FormFields("Dropdown5").Result)) Then
!FBCategory = ""
Else
!FBCategory = doc.FormFields("Dropdown5").Result
End If
If (IsNull(doc.FormFields("memFBExpSummary").Result)) Then
!FBExpSummary = ""
Else
!FBExpSummary = doc.FormFields("memFBExpSummary").Result
End If
If (IsNull(doc.FormFields("memFBExpDetail").Result)) Then
!FBExpDetail = ""
Else
!FBExpDetail = doc.FormFields("memFBExpDetail").Result
End If
If (IsNull(doc.FormFields("memProposedAct").Result)) Then
!ProposedAction = ""
Else
!ProposedAction = doc.FormFields("memProposedAct").Result
End If
If (IsNull(doc.FormFields("intNoSimilarExp").Result)) Then
!NoSimilarExp = ""
Else
!NoSimilarExp = doc.FormFields("intNoSimilarExp").Result
End If
If (IsNull(doc.FormFields("Dropdown6").Result)) Then
!FBPriority = ""
Else
!FBPriority = doc.FormFields("Dropdown6").Result
End If
If (IsNull(doc.FormFields("txtFBPOC").Result)) Then
!FBPOC = ""
Else
!FBPOC = doc.FormFields("txtFBPOC").Result
End If
If (IsNull(doc.FormFields("txtPOCExt").Result)) Then
!POCExt = ""
Else
!POCExt = doc.FormFields("txtPOCExt").Result
End If
If (IsNull(doc.FormFields("memNoAct").Result)) Then
!AnticipatedImpactNoAction = ""
Else
!AnticipatedImpactNoAction = doc.FormFields("memNoAct").Result
End If
If (IsNull(doc.FormFields("memIsAct").Result)) Then
!AnticipatedImpactIsAction = ""
Else
!AnticipatedImpactIsAction = doc.FormFields("memIsAct").Result
End If
.Update
End With
End If
doc.Close
strfile = Dir
Loop ' DO WHILE strFileName<>""
cnn.Close
MsgBox "Document(s)Imported!"
Cleanup:
If blnQuitWord Then appWord.Quit
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")
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
' Close the document if opened.
If (Not (doc Is Nothing)) Then
doc.Close
End If
GoTo Cleanup
End Sub