Question

Access 2007 merge form + subform to Word

Asked by: notpandora

I have created a form in Access which displays info required by a govt dept. It contains 1 form + 2 subforms (subforms are datasheets). Is there any way I can import it into a word template? I am having trouble getting the subforms with multiple lines in.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-08-05 at 20:26:01ID24630230
Tags

Access 2007

,

word 2007

,

mail merge

Topics

Microsoft Access Database

,

Microsoft Word

Participating Experts
2
Points
500
Comments
7

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Connect a subform to a datasheet subform
    I am using Access 97 I have a form called ?student & courses specific form? and a subform called ?student & course subform? (yes there are gaps!). The main form shows students personal details and the subform shows the courses they are doing this year. The subform ...
  2. Subform Datasheet
    Hi, I have a subform in datasheet style, how do I change the font size to make it smaller? Thanks
  3. Datasheet and subform
    I am trying to segment data from the same table into a form. The top half of the form I would like to display the summary fields in datasheet form. I want this to be the main form. On the bottom half I would like to have a form with all the details of the selected record from...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: GrahamSkanPosted on 2009-08-06 at 05:18:59ID: 25032364

Access Forms are different from VBA UserForms, and cannot be exported and imported as single items in a file in the same way that UserForms can , so it isn't clear what you are trying.

You can export the data behind a form to a Word document. It appears as a table in the Word document. You cannot export subform data in the same way. The Word document would require a sort of mini-table for each record on the main form. I think that you would need to use some VBA code to do it.

Mail merge is another way of pulling data from a database into a Word document, but again, it is only designed to cater for a single, non-hierarchical recordset. There is a non-VBA way round that, but most of the workarounds use VBA,

 

by: Helen_FeddemaPosted on 2009-08-06 at 15:36:52ID: 25038760

Here is a code sample that exports linked data to a Word document (an invoice with main invoice info in the top, and a table listing invoice details below.  The code is listed below; it uses a Word template

Private Sub cmdCreateInvoice_Click()
'Written by Helen Feddema 19-Aug-1999
'Last modified 22-Feb-2009
'Needs references to the DAO, Office, Word and Scripting Runtime libraries
 
   Dim appWord As Object
   Dim blnSaveNameFail As Boolean
   Dim curFreight As Currency
   Dim curSubtotal As Currency
   Dim curTotal As Currency
   Dim dblQuantity As Double
   Dim dbs As DAO.Database
   Dim doc As Word.Document
   Dim docs As Object
   Dim dteOrderDate As Date
   Dim dteRequiredDate As Date
   Dim dteShippedDate As Date
   Dim dteTodayDate As Date
   Dim fil As Scripting.File
   Dim fso As New Scripting.FileSystemObject
   Dim intCount As Integer
   Dim intReturn As Integer
   Dim lngOrderID As Long
   Dim lngProductID As Long
   Dim prps As Object
   Dim rst As DAO.Recordset
   Dim strBillToAddress As String
   Dim strBillToCityStateZip As String
   Dim strBillToCountry As String
   Dim strCompanyName As String
   Dim strCustomerID As String
   Dim strDefaultDocsPath As String
   Dim strDefaultTemplatesPath As String
   Dim strDiscount As String
   Dim strDoc As String
   Dim strDocsPath As String
   Dim strExtendedPrice As String
   Dim strMessage As String
   Dim strMessageTitle As String
   Dim strProductName As String
   Dim strPrompt As String
   Dim strSalesperson As String
   Dim strSaveName As String
   Dim strSaveNamePath As String
   Dim strShipAddress As String
   Dim strShipCityStateZip As String
   Dim strShipCountry As String
   Dim strShipName As String
   Dim strShipper As String
   Dim strShortDate As String
   Dim strTemplateName As String
   Dim strTemplateNameAndPath As String
   Dim strTemplatesPath As String
   Dim strTest As String
   Dim strTestFile As String
   Dim strTitle As String
   Dim strUnitPrice As String
   
On Error GoTo ErrorHandler
   
   'Create a Word instance to use for the invoice; uses the existing Word
   'instance if there is one, otherwise creates a new instance
    Set appWord = GetObject(, "Word.Application")
   
   'Keep Word invisible until the document is finished
   appWord.Visible = False
   
   'Run make-table queries to create tables to use for export;
   'I use make-table queries instead of select queries, because the
   'queries have a criterion limiting the Order ID to the one selected
   'on the form, and such parameter queries can't be used in a recordset.
   'Instead, the make-table queries are run to create tables which will
   'be used in the recordsets later in the code.
   DoCmd.SetWarnings False
   DoCmd.OpenQuery "qmakInvoice"
   DoCmd.OpenQuery "qmakInvoiceDetails"
   
   'Check that there is at least one detail item before creating invoice
   intCount = DCount("*", "tmakInvoiceDetails")
   Debug.Print "Number of Detail items: " & intCount
   
   If intCount < 1 Then
      strTitle = "Nothing to invoice"
      strPrompt = "No detail items for invoice; canceling"
      MsgBox prompt:=strPrompt, _
         buttons:=vbExclamation + vbOKOnly, _
         Title:=strTitle
      GoTo ErrorHandlerExit
   End If
   
   'Create recordset and get needed doc properties for this invoice
   Set dbs = CurrentDb
   Set rst = dbs.OpenRecordset("tmakInvoice", dbOpenDynaset)
   With rst
      'The Nz function is used to convert any Nulls to zeros or
      'zero-length strings, to prevent problems with exporting
      'to Word
      lngOrderID = Nz(![OrderID])
      Debug.Print "Order ID: " & lngOrderID
      strShipName = Nz(![ShipName])
      strShipAddress = Nz(![ShipAddress])
      strShipCityStateZip = Nz(![ShipCityStateZip])
      strShipCountry = Nz(![ShipCountry])
      strCompanyName = Nz(![CompanyName])
      strCustomerID = Nz(![CustomerID])
      strCompanyName = Nz(![CompanyName])
      strBillToAddress = Nz(![BillToAddress])
      strBillToCityStateZip = Nz(![BillToCityStateZip])
      strBillToCountry = Nz(![BillToCountry])
      strSalesperson = Nz(![Salesperson])
      dteOrderDate = Nz(![OrderDate])
      dteRequiredDate = Nz(![RequiredDate])
      dteShippedDate = Nz(![ShippedDate])
      strShipper = Nz(![Shipper])
      curSubtotal = Nz(![Subtotal])
      curFreight = Nz(![Freight])
      curTotal = Nz(![Total])
   End With
   rst.Close
   
   'Get selected Docs and Templates paths from database properties
   '(saved from controls on main menu)
   strDefaultDocsPath = appWord.Options.DefaultFilePath(wdDocumentsPath) & "\"
   strDocsPath = GetProperty("DocsPath", strDefaultDocsPath)
   Debug.Print "Docs path: " & strDocsPath
   strDefaultTemplatesPath = appWord.Options.DefaultFilePath(wdUserTemplatesPath) & "\"
   strTemplatesPath = GetProperty("TemplatesPath", strDefaultTemplatesPath)
   strTemplateName = "Northwind Invoice.dot"
   strTemplateNameAndPath = strTemplatesPath & strTemplateName
   
   'This date string is used in creating the invoice's save name
   strShortDate = Format(Date, "m-d-yyyy")
   'This date variable is used to print today's date on the invoice
   '(unlike a Word date code, it remains stable when the invoice is
   'reopened later)
   dteTodayDate = Date
   
   'Check for existence of template in templates folder,
   'and exit if not found
On Error Resume Next
 
   Set fil = fso.GetFile(strTemplateNameAndPath)
   If fil Is Nothing Then
      strTitle = "Template not found"
      strPrompt = "Can't find " & strTemplateName & " in " _
         & strTemplatesPath & "; canceling"
      MsgBox prompt:=strPrompt, _
         buttons:=vbInformation + vbOKOnly, _
         Title:=strTitle
      GoTo ErrorHandlerExit
   End If
   
On Error GoTo ErrorHandler
   
   Set docs = appWord.Documents
   Set doc = docs.Add(strTemplateNameAndPath)
   
   'Write information to Word custom document properties from
   'previously created variables
   Set prps = doc.CustomDocumentProperties
   prps.Item("TodayDate").Value = dteTodayDate
   prps.Item("OrderID").Value = lngOrderID
   prps.Item("ShipName").Value = strShipName
   prps.Item("ShipAddress").Value = strShipAddress
   prps.Item("ShipCityStateZip").Value = strShipCityStateZip
   prps.Item("ShipCountry").Value = strShipCountry
   prps.Item("CompanyName").Value = strCompanyName
   prps.Item("CustomerID").Value = strCustomerID
   prps.Item("CompanyName").Value = strCompanyName
   prps.Item("BillToAddress").Value = strBillToAddress
   prps.Item("BillToCityStateZip").Value = strBillToCityStateZip
   prps.Item("BillToCountry").Value = strBillToCountry
   prps.Item("Salesperson").Value = strSalesperson
   prps.Item("OrderDate").Value = dteOrderDate
   prps.Item("RequiredDate").Value = dteRequiredDate
   prps.Item("ShippedDate").Value = dteShippedDate
   prps.Item("Shipper").Value = strShipper
   prps.Item("Subtotal").Value = curSubtotal
   prps.Item("Freight").Value = curFreight
   prps.Item("Total").Value = curTotal
   
   'Highlight the entire Word document and update fields, so the data
   'written to the custom doc props is displayed in the DocProperty fields
   With appWord
      .Selection.WholeStory
      .Selection.Fields.Update
      .Selection.HomeKey Unit:=6
   End With
   
   'Go to table to fill with Details data
   With appWord.Selection
      .GoTo What:=wdGoToTable, Which:=wdGoToFirst, Count:=3, Name:=""
      .MoveDown Unit:=wdLine, Count:=1
   End With
   
   'Set up recordset of linked Details data to put in table on
   'Word invoice
   Set rst = dbs.OpenRecordset("tmakInvoiceDetails", dbOpenDynaset)
   
   'Save Details information to variables
   'Use Format function to apply appropriate formatting to
   'Currency and Percent fields
   With rst
      .MoveFirst
      Do While Not .EOF
         lngProductID = Nz(![ProductID])
         Debug.Print "Product ID: " & lngProductID
         strProductName = Nz(![ProductName])
         Debug.Print "Product Name: " & strProductName
         dblQuantity = Nz(![Quantity])
         Debug.Print "Quantity: " & dblQuantity
         strUnitPrice = Format(Nz(![UnitPrice]), "$##.00")
         Debug.Print "Unit price: " & strUnitPrice
         strDiscount = Format(Nz(![Discount]), "0%")
         Debug.Print "Discount: " & strDiscount
         strExtendedPrice = Format(Nz(![ExtendedPrice]), "$#,###.00")
         Debug.Print "Extended price: " & strExtendedPrice
         
         'Move through the table, writing values from the variables
         'to cells in the Word table
         With appWord.Selection
            .TypeText Text:=CStr(lngProductID)
            .MoveRight Unit:=wdCell
            .TypeText Text:=strProductName
            .MoveRight Unit:=wdCell
            .TypeText Text:=CStr(dblQuantity)
            .MoveRight Unit:=wdCell
            .TypeText Text:=strUnitPrice
            .MoveRight Unit:=wdCell
            .TypeText Text:=strDiscount
            .MoveRight Unit:=wdCell
            .TypeText Text:=strExtendedPrice
            .MoveRight Unit:=wdCell
         End With
         .MoveNext
      Loop
      .Close
   End With
   dbs.Close
   
   'Delete last, empty row
   Selection.SelectRow
   Selection.Rows.Delete
   
   'Check for existence of previously saved letter in documents folder,
   'and append an incremented number to save name if found
   strSaveName = "Invoice to " & strCompanyName & " for Order " _
      & lngOrderID & " on " & strShortDate & ".doc"
    
   intCount = 2
   blnSaveNameFail = True
   Do While blnSaveNameFail
      strSaveNamePath = strDocsPath & strSaveName
      Debug.Print "Proposed save name and path: " _
         & vbCrLf & strSaveNamePath
      strTestFile = Nz(Dir(strSaveNamePath))
      If strTestFile = strSaveName Then
         
         'Create new save name with incremented number
         blnSaveNameFail = True
       strSaveName = "Invoice " & CStr(intCount) & " to " & strCompanyName _
       & " for Order " & lngOrderID & " on " & strShortDate & ".doc"
 
         strSaveNamePath = strDocsPath & strSaveName
         intCount = intCount + 1
      Else
         blnSaveNameFail = False
      End If
   Loop
   
   'Ask whether user wants to save the document
   'If you prefer, you could eliminate the prompt and just
   'save the document with the save name automatically.
   strMessageTitle = "Save document?"
   strMessage = "Save invoice as '" & strSaveName & "'?"
   intReturn = MsgBox(strMessage, vbYesNoCancel + _
      vbQuestion + vbDefaultButton1, strMessageTitle)
   
   If intReturn = vbNo Then
      doc.Close savechanges:=wdDoNotSaveChanges
      GoTo ErrorHandlerExit
   ElseIf intReturn = vbYes Then
      doc.SaveAs strSaveNamePath
      appWord.Visible = True
   ElseIf intReturn = vbCancel Then
      GoTo ErrorHandlerExit
   End If
   
ErrorHandlerExit:
   Set appWord = Nothing
   'Close any open recordset or database, in case code stops because
   'of an error
   On Error Resume Next
   rst.Close
   On Error Resume Next
   dbs.Close
   Exit Sub
 
ErrorHandler:
   If Err = 429 Then
      'Word is not running; open Word with CreateObject
      Set appWord = CreateObject("Word.Application")
      Resume Next
   Else
      MsgBox "Error No: " & Err.Number & "; Description: " _
         & Err.Description
      Resume ErrorHandlerExit
   End If
 
End Sub
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:

Select allOpen in new window

 

by: Helen_FeddemaPosted on 2009-08-06 at 15:38:11ID: 25038769

For two sample databases (one in Access 2002-2003 format, the other in Access 2007 format) plus a set of Word templates, see my new ebook, Working with Word(http://shop.office-watch.com/aww/), which describes many ways to export Access data to Word documents.

 

by: Helen_FeddemaPosted on 2009-08-06 at 15:39:41ID: 25038777

The technique for the invoice is to write the main invoice data to doc properties in the Word document made from a template, and use TypeText to write the linked invoice detail data to rows in a table, as many as are needed for each invoice.

 

by: Helen_FeddemaPosted on 2009-08-06 at 15:43:18ID: 25038801

Here is a screen shot of the resulting Word document:

 

by: notpandoraPosted on 2009-08-09 at 04:39:54ID: 25053809

Sorry, I have been offline, I will try this tomorrow and do points by Tuesday.

 

by: notpandoraPosted on 2009-08-11 at 19:59:55ID: 31612243

Thanks so much for your help!

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...