Results 1 to 10 of 10
  1. #1
    fekrinejat is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    29

    Print Word doc using Access fields

    Hello
    I need a solution to print a word document out using access fields


    any idea ?

  2. #2
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,538
    Look at the mail merge wizard in Word and use a query in Access as the record source for the data to insert.

    Altenatively, you could use this approach

    http://www.datapigtechnologies.com/f...mailmerge.html

  3. #3
    rankhornjp is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jul 2011
    Posts
    46
    This is what I use.

    Code:
    Private Sub printForm()
    'Open up form and fill it in with information from database.
    
    
    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
    
    
    'If word isn't open, create an instance 
    
    
        Set doc = appWord.Documents.Open("\\Location of file\filename.doc", , True)
    
    
    With doc
    .FormFields("TextBox in Word").Result = Field from Database
    .FormFields("firstName").Result = Me!pFname
    .FormFields("lastName").Result = Me!pLname
    .FormFields("middleName").Result = Me!pMi
    .FormFields("streetAddress").Result = Me!pAddress1
    .FormFields("cityAddress").Result = Me!pCity
    .FormFields("stateAddress").Result = Me!pState
    .FormFields("zipAddress").Result = Me!pZip
    .FormFields("numberHome").Result = Me!pPhone1
    .FormFields("numberCell").Result = Me!pPhone2
    .Visible = True
    .Activate
    
    
    End With
    
    
    Set doc = Nothing
    Set appWord = Nothing
    
    
    Exit Sub
    
    errHandler:
    MsgBox Err.Number & ": " & Err.Description
    
    End Sub

  4. #4
    fekrinejat is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    29
    Thanks alansidman..

    Dear rankhornjpi
    i couldn't use your code , i created a module and added microsoft word activex
    in reference menu and did run the code , there was error on Me!pFname
    tells me invalid use of Me keyword .. It even didn't give me error on existing doc file ..
    would you tell me how to run it , sounds great by this code..
    it seems i had to create unbounded fields in doc .. right ?

  5. #5
    rankhornjp is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jul 2011
    Posts
    46
    Quote Originally Posted by fekrinejat View Post
    Thanks alansidman..

    Dear rankhornjpi
    i couldn't use your code , i created a module and added microsoft word activex
    in reference menu and did run the code , there was error on Me!pFname
    tells me invalid use of Me keyword .. It even didn't give me error on existing doc file ..
    would you tell me how to run it , sounds great by this code..
    it seems i had to create unbounded fields in doc .. right ?
    Yes


    "Me!" references the current table or form (Table "People" in my case) and "pFname" is a field in that table/form.

    Are you pulling all the information from 1 table?

    If you are pulling data from multiple tables, then you have to create a recordset to pull data from.

  6. #6
    fekrinejat is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    29
    I have a form and subform (two tables - one to many relationship)
    would you customize your code in this situation ? creating a recordset ..

  7. #7
    fekrinejat is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    29
    Sorry about the crazy question , it's pretty nice and simple
    Thanks

  8. #8
    fekrinejat is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    29
    But how to make firstName field in word ?
    fields are customized for individual jobs ..

  9. #9
    rankhornjp is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jul 2011
    Posts
    46
    Quote Originally Posted by fekrinejat View Post
    But how to make firstName field in word ?
    fields are customized for individual jobs ..
    I used legacy text boxes under the developer tab(you have to turn it on under "options" if you haven't already).

    Create the box, then double click it to bring up the properties and change the bookmark name to whatever you want to reference in your code.
    Last edited by rankhornjp; 03-12-2013 at 09:19 AM.

  10. #10
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,538
    Here is the manual way of doing a mail merge using word and Access

    http://www.youtube.com/watch?v=QaCaBB8cLO8

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

Similar Threads

  1. Fields Go Blank On Print Preview
    By VariableZ in forum Reports
    Replies: 4
    Last Post: 03-07-2013, 11:00 AM
  2. Call word object and import word fields
    By silverspr in forum Programming
    Replies: 3
    Last Post: 12-10-2012, 11:32 PM
  3. Word Merge and Print
    By labessade in forum Programming
    Replies: 5
    Last Post: 10-15-2012, 01:13 PM
  4. Access to Word - Multiple Word Templates?
    By alpinegroove in forum Programming
    Replies: 11
    Last Post: 06-12-2012, 04:42 PM
  5. OLE and Text Fields with MS Word
    By WBlohm in forum Access
    Replies: 1
    Last Post: 09-10-2010, 07:53 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