I have 100+ word documents filled out by our engineers.
I am looking to upload the documents into a Access Database rather then manual entry
I have been looking about and found a guide on how to do this but I think some parts of the code need updating.
If someone can tell me where I am going wrong with this or suggest another code that would be a great help.
The forms are kept in P:\Engineer Forms\ and my database is called TI Information.laccdb and also kept in the P:\ drive.
Code:
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
On Error GoTo ErrorHandling
strDocName = "P:\Engineer Forms\" & _
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=J:\" & _
"TI Information.laccdb;"
rst.Open "TI Information", cnn, _
adOpenKeyset, adLockOptimistic
With rst
.AddNew
!SiteID = docx.FormFields("fldsiteid").Result
!TIDate = docx.FormFields("flddate").Result
!EngineerName = docx.FormFields("fldname").Result
!Numberofengineers = docx.FormFields("fldnumber").Result
!Timeonsite = docx.FormFields("fldtimeon").Result
!Timeoffsite = docx.FormFields("fldtimeoff").Result
!Floorwalktimeon = docx.FormFields("fldwalkon").Result
!Floorwalktimeoff = docx.FormFields("fldwalkoff").Result
!Scopeofwork = docx.FormFields("fldwork").Result
!Totalnumberofhandsets = docx.FormFields("fldhandsets").Result
.Update
.Close
End With
doc.Close
If blnQuitWord Then appWord.Quit
cnn.Close
MsgBox "TI form 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