You can export data from your Access database to a Microsoft Word document by using the Export — RTF File Wizard. This article explains how to use the Export — RTF File Wizard and how to save your export settings as a specification for later reuse.
In this article
-
Exporting data to Word: the basics
-
Export data to Word
-
Understand how Access exports objects to Word
-
What else should I know?
Exporting data to Word: the basics
You can export a table, query, form, or report to Microsoft Word. When you export an object by using the Export — RTF File Wizard, Access creates a copy of the object’s data in a Microsoft Word Rich Text Format file (*.rtf). For tables, queries, and forms, the visible fields and records appear as a table in the Word document. When you export a report, the wizard exports the report data and layout — it tries to make the Word document resemble the report as closely as possible.
-
Start the operation from Access To export data from Access to Word, you need to work in Access. There is no functionality in Word that can import data from an Access database. You also cannot save an Access database or table as a Word document by using the Save As command in Access.
-
Objects you can export You can export a table, query, form, or report. You can also export only the records selected in a view. You cannot export macros and modules. When you export a form or datasheet that contains subforms or subdatasheets, only the main form or datasheet is exported. You need to repeat the export operation for each subform and subdatasheet that you want to view in Word. Conversely, when you export a report, subforms and subreports that are included in the report are exported, along with the main report.
-
Outcome of the operation The Export — RTF File Wizard always exports formatted data. This means that only the fields and records that are visible in an object or view are exported along with the display format settings. Columns and records that are hidden, due to filter settings, are not exported. For a report, the layout of the report is also preserved when it is exported.
-
Merging with an existing document When you export from Access to a Word document, the data is always exported into a new Word file. If you want the data to be inserted into an existing Word document, you must first export it from Access into a new Word document, and then copy the data from the new Word document and paste it into the existing document. Alternatively, you can copy rows directly from an Access table, query, form, or report, and then paste them into your existing document.
Export data to Word
The process of exporting data to a Word document follows these broad steps:
-
Prepare your source data for the export. As part of this step, you make sure that your data does not contain errors, and you decide whether to export some or all of the data in your source table.
-
Run the Export — RTF File Wizard.
-
Optionally save your settings as an export specification for later reuse.
The steps in the following sections explain how to perform each task.
Prepare for the export
-
Open the source Access database.
-
In the Navigation Pane, select the object that contains the data you want to export.
You can export a table, query, form, or report.
-
Review the source data to ensure that it does not contain error indicators (green triangles) or error values, such as #Num.
Ensure that you have resolved any errors before you export the data to Word. Otherwise, you will find that such values are replaced with a null value.
-
If the destination Word document exists and is open, close it before you continue. The wizard prompts you before overwriting the document.
Note: You cannot append data to an existing Word document.
-
In the Access database, if you want to export only a portion of a table, query, or form, open the object and select just the records you want.
Export the data
-
On the External Data tab, in the Export group, click Word.
-
The Export — RTF File export wizard opens.
Note: The Export commands are available only when a database is open.
-
In the Export — RTF File wizard, specify the name of the destination file.
-
The wizard always exports formatted data. If you want to view the Word document after the export operation is complete, select the Open the destination file after the export operation is complete check box.
-
If you selected the records that you want to export before you started the export operation, you can select the Export only the selected records check box. However, if you want to export all the records in the view, leave the check box cleared.
Note: This check box appears unavailable (dimmed) if no records are selected.
-
Click OK.
-
If the destination document exists, you are prompted to click Yes to overwrite the file. Click No to change the name of the destination file, and then click OK again.
Access exports the data and opens the destination document in Word, depending on the export options you specified in the wizard. Access also displays the status of the operation on the final page of the wizard.
Understand how Access exports objects to Word
The following table describes how Access exports various objects and values to Word. This can help you determine what is going wrong if the export operation is not working the way you expect.
Item |
Export considerations |
Field names |
When you export a table, a query, or a form, the field names are placed in the first row of the table in the Word document. When you export a report, the placement of the field names in the Word document varies with the report layout. |
Multivalued fields |
A field in Access that supports multiple values is exported to a single column in Word. The values are separated by commas (,). |
Pictures, objects, and attachments |
All graphical elements — logos, data in OLE object fields, and attachments that are part of the source data — are not exported. |
Graphs |
Microsoft Graph objects are not exported. |
Expressions |
Expressions are not exported to the Word document. Only the results of the expressions are exported. |
Subforms and subdatasheets |
When you export a form or datasheet, only the main form or datasheet is exported. You must repeat the export operation for each subform and subdatasheet. |
What else should I know?
-
For information on how to save the details of your export into a specification that you can reuse later, see the article Save the details of an import or export operation as a specification.
-
For information on how to run saved export specifications, see the article Run a saved import or export operation.
-
For information on how to schedule specifications to run at specific times, see the article Schedule an import or export operation.
-
For information on how to change a specification name, delete specifications, or update the names of source files in specifications, see the article Manage Data Tasks.
Top of Page
TL;DR Generate Word/PDF documents from SQL Server,
Oracle, and MySQL
using SQL queries.
In every organization, database plays an important role in holding the
entire organization’s data across functions/departments. Organizations
create a variety of documents from this data including sales proposals,
invoices, contracts, compliance documents, and NDAs, etc.
Some industries such as legal, mortgage, and real estate are inherently
document-intensive and documents play a central role in their day-to-day
transactions. The document-generation requirements tend to vary a lot from
on-demand creation of a single document to bulk generation of thousands of documents in one go.
The generated documents are shared with internal and external
stakeholders including customers, vendors, and partners. It could be a simple mail or part of a
complex business process that involves e-sign, approvals, etc.
In essence, database to PDF and Word document generation and their distribution
is an essential job in every organization.
Challenges in Document generation from Database
In traditional databases, data inside the database is stored in tables and
they have a logical connection among them. Hence, Database solutions don’t
have document design capabilities. NoSQL/document databases store data in
JSON or a JSON-like documents and not great for document generation either.
If you are a master of SQL commands, you have a lot of choices including
off-the-shelf PL/SQL packages. But for a non-technical user/business user,
the options are limited. The first option is to knock on the IT department door
for help. However, business documents undergo frequent changes, and getting
IT bandwidth every time for document generation is difficult.
Hence, you find business users tend to look for a solution that allows them
to
-
Create/modify templates easily conforming to the organization’s brand and
design guidelines. - Generate documents with a click of a button.
Let’s look at the tools for addressing these requirements.
Common Tools for Database PDF
The most common solutions being used are not built for database documents generation
and hence offer only a little automation.
Reporting/BI tools:
Tools such as Tableau, Jasper,
Crystal reports generate reports but they lack in document design. These
are best suited for creating interactive reports. Though they make the
document generation easy, business users still need to depend on IT help
for template creation and template changes.
Publishing tools:
Data merge and Mail merge functionality offered by publishing tools such as
Indesign, Microsoft Word is good only for basic document merge. For
example, if you are looking to create a nice report with bullets,
conclusions, other written text, and pre-formatted numbers then a
publishing tool is not the right choice. Moreover, these tools have several
limitations including the inability to suppress blank rows, date &
number formatting errors, etc.
EDocGen for Database to Word and PDF Generation
The system addresses the creation of documents from the databases in a very
elegant fashion. Business users can create/edit templates in their favorite
editors. With a DIY interface, it can populate database data into templates
to generate documents. Users can use existing documents as templates for
document generation. Thus as in previous approaches, they don’t have to go through the
pain of template creation from
scratch or employing developers for template creation.
EDocGen offers the dynamic population of text, tables, hyperlinks, content blocks, and images.
The system also supports the BLOB population into the template. Thus the
extremely flexible to cater to different kinds of business documents including contracts, invoices, etc.
As it
is a cloud application, it enhances collaboration, intelligence, and
mobility of your team to work from anywhere on any device.
Let’s see how it creates documents from different databases.
- As a first step, select the database from which you want to generate documents.
- Enter the connection
details. You can connect to on-premise as well as cloud databases to the system. - Enter the query to extract data from the database.
If you cannot enter connection details, alternatively you can extract database data in XML/JSON/Excel
formats and use this data for document automation.
SQL Server: Using FOR XML and FOR JSON, retrieve SQL Server data in XML /JSON format
with a simple SELECT query
and populate results into templates for document generation. Refer to SQL to PDF, SQL to Word for details
on how to go about creating PDF and Word documents from SQL Server.
You can also use API integration for on-demand document generation from SQL Server.
SELECT Title,
FirstName,
MiddleName,
LastName,
Suffix
FROM Person.Person
FOR XML AUTO
GO
MySQL: MySQL allows you to retrieve SQL data into a local CSV file through a simple SELECT query.
Populate that into the template for Database documents generation.
You can also export query data into JSON file as well as shown below using
‘JSON_OBJECT’ function.
SELECT CONCAT('[',GROUP_CONCAT(JSON_OBJECT('ID', department_id, 'name', department_name)),']')
FROM departments
Refer to JSON to Word for details about JSON population into Word template.
Oracle: Using XMLElement and XMLForest, you can export XML data from Oracle
database. Use EDocGen to populate XML data into your template to generate
multiple documents.
Refer to Oracle to PDF, Oracle to Word for details
on how to go about creating PDF and Word documents from the Oracle database.
Document Databases: Document databases such as MongoDB store
data as documents. Thus querying MongoDB data is not straightforward.
You can retrieve the data using db.collection.find() method. Let’s say you have a «students» collection.
Enter «db.students.find()» in the select query input area to retrieve all records of students.
Online Databases: Databases such as Knack, Caspio, etc. offer Zapier
integration. Again here as well integrate with EDocGen to generate
documents. For example, you can set-up a trigger for every new record entry
into the database. This trigger fires and creates a document every time a
record gets added to the database. Even the delivery of documents to
recipients via email can be automated.
In the next step of document generation, map the dynamic fields to query columns. If the names match,
the system auto-maps the fields. Thus you avoid
costly data transformations. Changing of table structure would never affect the document generation.
You can
generate thousands of documents in seconds.
In summary, EDocGen document generation software is the perfect solution
for the database to PDF file and Word document creation. You can use both Word and
PDF templates for database documents creation.
- Remove From My Forums
-
Question
-
User-946136194 posted
i have a small app where i enter data on a form and it gets stored in a database.
each time i save a users data, i want to click a button which should (1) open a word template doc, (2) get certain data like name/address from database and populate the word doc.
anyone help me out here? thanks!
Answers
-
User-1910946339 posted
There are several ways to do this sort of thing. I have used the information from a database to set the properties of a Word document. That Word document has fields in it which show the values of the properties. The advantage of this
is that you do not run Word on your server, the properties are just properties of the file.You can create a Word document with booksmarks in it and then use Word automation to populate those bookmarks with information from the database. This would need Word on the server which is not supported (many people claim that extremely scary and
bad things will happen if you install Word on a server, personally, I have never seen the slightest problem but I only have very low usage)You can create a mailmerge document and then merge it using data from a query. Again, you would need Word on the server.
If you are using Word 2007 then you could create a document using the docx format, again without needing Word on your server.
Office-watch.com has squillions of examples of this sort of thing, mainly using Access and Word but the principles are the same.
-
Marked as answer by
Thursday, October 7, 2021 12:00 AM
-
Marked as answer by
In this article I will explain with an example, how to export data from database to Word document in ASP.Net Core MVC.
The data from the database is fetched using Entity Framework and dynamic HTML string is generated using StringBuilder class.
Finally, the generated HTML string will be exported to Word document in ASP.Net Core MVC.
Database
Here I am making use of Microsoft’s Northwind Database. You can download it from here.
Namespaces
You need to import the following namespace.
Model
The Model class consists of the following four properties.
public class Customer
{
public string CustomerID { get; set; }
public string ContactName { get; set; }
public string City { get; set; }
public string Country { get; set; }
}
Database Context
Once the Entity Framework is configured and connected to the database table, the Database Context will look as shown below.
using Microsoft.EntityFrameworkCore;
namespace Export_Data_Database_Word_MVC_Core
{
public class DBCtx : DbContext
{
public DBCtx(DbContextOptions<DBCtx> options) : base(options)
{
}
public DbSet<Customer> Customers { get; set; }
}
}
Controller
The Controller consists of following two Action methods.
Action method for handling GET operation
Inside this Action method, the Top 10 records are fetched from the Customers table using Entity Framework and returned to the View.
Action method for handling the Word Document Export and Download operation
This Action method is executed when the Export Button is clicked.
Note: The following Action method performs File Download operation. Hence the return type is set to FileResult. For more details on FileResult, please refer my article FileResult return type in ASP.Net Core MVC.
Inside this Action Method, the Top 10 Customer records are fetched from the Customers Table using Entity Framework and then using the StringBuilder class, a string consisting of an HTML Table is generated.
Finally, the HTML string is converted to Byte Array and exported and downloaded as Word document using the File function.
public class HomeController : Controller
{
private DBCtx Context { get; }
public HomeController(DBCtx _context)
{
this.Context = _context;
}
public IActionResult Index()
{
return View(this.Context.Customers.Take(10).ToList());
}
[HttpPost]
public FileResult Export()
{
List<object> customers = (from customer in this.Context.Customers.Take(10)
select new[] {
customer.CustomerID,
customer.ContactName,
customer.City,
customer.Country
}).ToList<object>();
//Building an HTML string.
StringBuilder sb = new StringBuilder();
//Table start.
sb.Append(«<table border=’1′ cellpadding=’5′ cellspacing=’0′ style=’border: 1px solid #ccc;font-family: Arial; font-size: 10pt;’>»);
//Building the Header row.
sb.Append(«<tr>»);
sb.Append(«<th style=’background-color: #B8DBFD;border: 1px solid #ccc’>CustomerID</th>»);
sb.Append(«<th style=’background-color: #B8DBFD;border: 1px solid #ccc’>ContactName</th>»);
sb.Append(«<th style=’background-color: #B8DBFD;border: 1px solid #ccc’>City</th>»);
sb.Append(«<th style=’background-color: #B8DBFD;border: 1px solid #ccc’>Country</th>»);
sb.Append(«</tr>»);
//Building the Data rows.
for (int i = 0; i < customers.Count; i++)
{
string[] customer = (string[])customers[i];
sb.Append(«<tr>»);
for (int j = 0; j < customer.Length; j++)
{
//Append data.
sb.Append(«<td style=’border: 1px solid #ccc’>»);
sb.Append(customer[j]);
sb.Append(«</td>»);
}
sb.Append(«</tr>»);
}
//Table end.
sb.Append(«</table>»);
return File(Encoding.UTF8.GetBytes(sb.ToString()), «application/vnd.ms-word», «Grid.doc»);
}
}
View
Inside the View, in the very first line the Customer Model is declared as IEnumerable which specifies that it will be available as a Collection.
Displaying the Records
For displaying the records, an HTML Table is used.
A loop will be executed over the Model which will generate the HTML Table rows with the Customer records.
Exporting database data to Word Document
Below the HTML Table, there is an HTML Submit button enclosed inside a Form which has been created with following ASP.Net Tag Helpers attributes.
asp-action – Name of the Action. In this case the name is Export.
asp-controller – Name of the Controller. In this case the name is Home.
method – It specifies the Form Method i.e. GET or POST. In this case it will be set to POST.
When the Submit button is clicked, the Form is submitted.
@model IEnumerable<Export_Data_Database_Word_MVC_Core.Models.Customer>
@addTagHelper*, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name=»viewport» content=»width=device-width» />
<title>Index</title>
</head>
<body>
<h4>Customers</h4>
<hr />
<div id=»Grid»>
<table cellpadding=»5″ cellspacing=»0″ style=»border: 1px solid #ccc;«>
<tr>
<th style=»background-color: #B8DBFD;border: 1px solid #ccc»>CustomerID</th>
<th style=»background-color: #B8DBFD;border: 1px solid #ccc»>ContactName</th>
<th style=»background-color: #B8DBFD;border: 1px solid #ccc»>City</th>
<th style=»background-color: #B8DBFD;border: 1px solid #ccc»>Country</th>
</tr>
@foreach (var customer in Model)
{
<tr>
<td style=»border: 1px solid #ccc»>@customer.CustomerID</td>
<td style=»border: 1px solid #ccc»>@customer.ContactName</td>
<td style=»border: 1px solid #ccc»>@customer.City</td>
<td style=»border: 1px solid #ccc»>@customer.Country</td>
</tr>
}
</table>
</div>
<br />
<form method=»post» asp-action=»Export» asp-controller=»Home»>
<input type=»submit» id=»btnSubmit» value=»Export» />
</form>
</body>
</html>
Screenshots
HTML Table
Exported Word document
Downloads
Check out some options how db files might be converted to docx format.
It does not make much sense to convert a database (typically .db file) to a Word document format (.doc, .docx). The only option perhaps would be to convert db to csv or similar text format, and copy paste the text to Word. But that is highly irregular.
Updated: September 16, 2022
Unfortunately, there is no detailed software record in the database for this conversion.
Additional links: Open db file, Open docx file
DB
A db file extension is typically used for databases. They can be in many different formats but most are based on classical database engines like dBase.
Files with db file extension may also well be backups of chat history (message database) from WhatsApp Messenger app for BlackBerry and Windows Phone.
Files with db file extension are generally databases. One of the database formats that uses the db file extension is created by Corel Paradox.
Files with db extension can be also commonly found as thumbnail databases from Windows operating system. Used to speedup loading images.
A db file extension is related to the Enpass, a password management software for various platforms. A db file stores encrypted password database.
DOCX
Files with docx file extension are documents written and saved using Microsoft Word word processor edition 2007 or later. DOCX format replaced the previously used DOC format, moving from binary files to Open XML schema-based documents. They are supported in almost every modern word-processing tools.
Back to conversion search