Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2013
    Posts
    20

    Question Unanswered: Form Fields in MS Word 2010

    Here is a commonly used script for inserting word fields into Access from a dialogue box. Works great for MS Word 2003. Having trouble identifying the fields in MS Word 2010. Any help would be appreciated. The error is no fields in MS Word basically exist. I assume it is looking at the tag label in word. Did not see anything else to identify the field in MS Word 2010 for reference to the form field.

    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 dialog As FileDialog
    On Error GoTo ErrorHandling

    Set dialog = Application.FileDialog(msoFileDialogOpen)

    With dialog
    .AllowMultiSelect = False
    .Show
    strDocName = .SelectedItems.Item(1)
    End With
    Set appWord = GetObject(, "Word.Application")
    Set doc = appWord.Documents.Open(strDocName)

    cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=C:\Users\kenny\Desktop\" & _
    "DBPRACTICE1.mdb;"
    rst.Open "Personal", cnn, _
    adOpenKeyset, adLockOptimistic

    With rst
    .AddNew
    !Surname = doc.FormFields("fldSurname").Result
    !GivenNames = doc.FormFields("fldGivenNames").Result
    !Address = doc.FormFields("fldAddress").Result
    !City = doc.FormFields("fldCity").Result
    !Phone = doc.FormFields("fldPhone").Result
    .Update
    .Close
    End With
    doc.Close
    If blnQuitWord Then appWord.Quit
    cnn.Close
    MsgBox "Contract 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

  2. #2
    Join Date
    Oct 2013
    Posts
    20
    I found my problem. In MS Word 2010 you need to insert the form field from the legacy toolbar. https://www.dropbox.com/s/s6woi9ni2w...2013.27.29.png Here is my dropbox if you want to see what I mean. Other than that the code works great.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •