Results 1 to 2 of 2
  1. #1
    j2tec is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Posts
    1

    Angry Form/Subform to Word via VBA

    I am having a hard time trying to get a form and subform to populate a prebuilt word document. The main form is pretty simple and I have that functioning correctly using bookmarks. The subform is a datasheet & I am able to get the top line only to populate bookmarks.

    The main form contains patient contact info and the subform contains an inventory datasheet with fields such as Description, Serial Number, Quantity, Etc.

    Ideally I'd like the subform to populate a table in word that already has the columns setup and will add the appropriate number of rows as needed, based on the number of records in the datasheet.

    I am using the following code, although I have trued adding some loop statements I have found online to no avail, so I removed the....Any help would be greatly appreciated...
    Option Compare Database

    Private Sub cmdPrint_Click()

    'Print customer slip for current customer.

    Dim appWord As Word.Application

    Dim doc As Word.Document

    'Avoid error 429, when Word isn't open.

    On Error Resume Next

    Err.Clear

    'Set appWord object variable to running instance of Word.

    Set appWord = GetObject(, "Word.Application")

    If Err.Number <> 0 Then

    'If Word isn't open, create a new instance of Word.

    Set appWord = New Word.Application

    End If

    Set doc = appWord.Documents.Open("C:\Docs\InvSheet.docx", , True)

    With doc

    .FormFields("Name").Result = Me!Name
    .FormFields("Room").Result = Me!Room
    .FormFields("MoveInDate").Result = Me!MoveInDate
    .FormFields("RESIDENTINVENTORYID").Result = subfMoveInInventory!RESIDENTINVENTORYID
    .FormFields("ResidentID").Result = subfMoveInInventory!ResidentId
    .FormFields("PropertyItem").Result = subfMoveInInventory!PropertyItem
    .FormFields("Serial").Result = subfMoveInInventory!Serial
    .FormFields("Quanty").Result = subfMoveInInventory!Quanty
    .FormFields("DisposalDate").Result = subfMoveInInventory!DisposalDate


    .Visible = True

    .Activate

    End With

    Set doc = Nothing

    Set appWord = Nothing



    Exit Sub

    errHandler:

    MsgBox Err.Number & ": " & Err.Description


    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    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. Import Word form to Access form as new record (user friendly)
    By bbrazeau in forum Import/Export Data
    Replies: 1
    Last Post: 04-30-2013, 12:00 PM
  2. Replies: 8
    Last Post: 04-14-2013, 01:33 PM
  3. Call word object and import word fields
    By silverspr in forum Programming
    Replies: 3
    Last Post: 12-10-2012, 11:32 PM
  4. Access to Word - Multiple Word Templates?
    By alpinegroove in forum Programming
    Replies: 11
    Last Post: 06-12-2012, 04:42 PM
  5. Replies: 5
    Last Post: 07-16-2010, 10:12 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