I am trying to take the user input from a Word form and place it into an Access DB. I have the document and database in the same folder on my C drive. I am getting an error at :
rst.Fields("Ful lName") = doc.FormFields( "txtYourName"). Result
It is not getting the data from the content control.
Here is all of the of the code:
Any suggestions would be great. Thanks
rst.Fields("Ful lName") = doc.FormFields( "txtYourName"). Result
It is not getting the data from the content control.
Here is all of the of the code:
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 = "C:\SampleForm\" & _
InputBox("Enter the name of the Word document you want to import:", "Import document")
Set appWord = GetObject(, "Word.Application")
appWord.Visible = True
Set doc = appWord.Documents.Open(strDocName)
Set cnn = CurrentProject.Connection
rst.Open "FormData", cnn, adOpenKeyset, adLockOptimistic
rst.AddNew
rst.Fields("FullName") = doc.FormFields("txtYourName").Result
rst.Fields("Address") = doc.FormFields("txtYourAddress").Result
rst.Fields("Phone") = doc.FormFields("txtYourPhone").Result
rst.Fields("Male") = doc.FormFields("txtMale").Result
rst.Fields("Female") = doc.FormFields("txtFemale").Result
rst.Update
rst.Close
doc.Close
If blnQuitWord Then appWord.Quit
cnn.Close
MsgBox "Request Imported"
Cleanup:
Set rst = 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 5491
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
Comment