Hello
I need a solution to print a word document out using access fields
any idea ?
Hello
I need a solution to print a word document out using access fields
any idea ?
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
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
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 ?
YesThanks 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 ?
"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.
I have a form and subform (two tables - one to many relationship)
would you customize your code in this situation ? creating a recordset ..
Sorry about the crazy question , it's pretty nice and simple
Thanks
But how to make firstName field in word ?
fields are customized for individual jobs ..
Last edited by rankhornjp; 03-12-2013 at 09:19 AM.
Here is the manual way of doing a mail merge using word and Access
http://www.youtube.com/watch?v=QaCaBB8cLO8