Results 1 to 2 of 2
  1. #1
    bbrazeau is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    101

    Import Word form to Access form as new record (user friendly)

    I have attached a very simple word doc and database for reference. I have seen a lot of posts in this forum regarding attempts to do what I would like to do, but none are user friendly at all.
    It seems to me this should be a fairly easy thing to do. I want to click a button on my form and fill in a new record by retrieving a word document that has the info needed. If you look at my Test example, I have 3 fields: a date, a combobox choice, and a checkbox. I have code that is supposed to extract the info from the word doc and form a new record, but I get an error "User-defined type not defined" the line of code it hangs on is: "Dim appWord As Word.Application"

    The code was taken from a tutorial on "2000". Does any one have a more up to date version that works with "2007"? Thank you for any help.
    Private Sub CmdTest_Click()
    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:\Users\bbrazeau\Desktop\Test"
    Set appWord = GetObject(, "Word.Application")
    Set doc = appWord.Documents.Open(strDocName)
    cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=C:\Users\bbrazeau\Desktop\" & _
    "Test.accdb;"
    rst.Open "tblContracts", cnn, _
    adOpenKeyset, adLockOptimistic
    With rst
    .AddNew
    !TestDate = doc.FormFields("TestDate").Result
    !TestText = doc.FormFields("TestText").Result
    !TestChoice = doc.FormFields("Check1").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
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    51,123
    Need to set VBA reference to Microsoft Word 12.0 Object Library

    From the VBA editor: Tools > References > scroll down and check the reference
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Creating a user friendly DB and tightning up Security
    By WayneSteenkamp in forum Access
    Replies: 12
    Last Post: 03-20-2012, 02:33 AM
  2. Import Word Docs as Form Template
    By Spectre50 in forum Forms
    Replies: 0
    Last Post: 03-05-2012, 01:51 PM
  3. User friendly complex names
    By MatrixRage in forum Database Design
    Replies: 1
    Last Post: 08-10-2010, 09:41 AM
  4. Creating User friendly Search Forms
    By BernardKane in forum Forms
    Replies: 7
    Last Post: 01-29-2010, 11:28 AM
  5. Help!!! user friendly forms/date entry
    By megank in forum Access
    Replies: 3
    Last Post: 03-31-2009, 09:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums