Using ODBC with Microsoft Word -...

64
ANSWERS ODBC Seminar Copyright 2001-2006 Data Resources Corporation Page 1 of 64

Transcript of Using ODBC with Microsoft Word -...

ANSWERS ODBC Seminar

Copyright 2001-2006Data Resources Corporation

Page 1 of 57

ANSWERS ODBC Seminar

What is ODBC?ODBC stands for Open DataBase Connectivity. The files created by the Answers software are COBOL files stored in Answers specific formats. In order to be able to look at the data in any of the Answers files, you have to have an Answers programs. Even other COBOL programs would not be able to properly interpret the data without a “file layout” or description of the files. ODBC allows a file format or description to be given to ODBC compatible programs, such as Microsoft Word, Microsoft Excel, Cyrstal Report Writer, etc. so that they can understand and read the data out of the Answers files. This makes it possible for you to create your own reports and extract spreadsheet information out of your Answers data.

What do I need to use ODBC?In order to use ODBC, you must have:

1. An AcuCobol ODBC license. This is an optional license that needs to be installed and configured on a PC. This license can be purchased through Data Resources Corporation and instructions are available in our ODBC User’s Guide, available at www.drcanswers.com/support.htm on how to install and configure the software.

2. You must have a software application that is ODBC capable. This software must be able to work with ODBC and extract data. Microsoft Office applications, such as Word, Excel, and Access are all ODBC capable. Other software applications such as Crystal Report Writer are available as well.

How Do I Get Started?The best way to learn to use ODBC is through hands-on experience. At first you may struggle, but learn the overall concepts and in no time, you will be creating reports and spreadsheets with ODBC like a pro. Knowing what files to use to get the information you need is important. You can download our ODBC User’s Guide at www.drcanswers.com/support.htm which includes a file list and information on what is in each file as well as general concept information for using ODBC.

Page 2 of 57

ANSWERS ODBC Seminar

Using ODBC with Microsoft Excel

Microsoft Excel can be used to extract information from ANSWERS into a spreadsheet format.

Example 1: Create Spreadsheet showing all Customers with GM < 20%This example will pull all customers who have a gross margin percent less than 20% into a spreadsheet. This example will use the Customer Master File to retrieve it’s information.

ANSWERS Files Used: ARFCUST

1. Start Microsoft Excel and begin with a blank worksheet.

2. From the menu bar, click on Data, then Import External Data, then New Database Query. This will start Microsoft Query.

3.

Select the data source that you wish to pull information from and then click on OK. You will normally have a database named “Answers Data”.

4.

Page 3 of 57

ANSWERS ODBC Seminar

The available files in the data source will be displayed. Click on the + beside of the file(s) that you wish to use to see the actual fields available in each file. Select the “columns” for the query. When data is pulled into an Excel spreadsheet, the columns of the spreadsheet will be the fields that you select to include. The rows of the spreadsheet will be the customer records that are selected to be included. The columns of the spreadsheet will be ordered in left to right order, using the columns displayed in top to bottom order.

5.

Once you have selected all of the fields you want, click on Next to continue.

6.

Page 4 of 57

ANSWERS ODBC Seminar

The Query Wizard next displays the filter data screen, allowing us to enter criteria for selecting the records that we wish to be returned. From the fields that we chose to include in our query, we can limit the number of records being returned. We are choosing to display the customer’s Year to Date sales and gross margin and Last Year’s sales and gross margin, but we only want to display customers whose Year to Date gross margin is less than 20%. Once you have finished entering your criteria, click Next to continue.

7.

Next, select the field that you wish to sort the customers by. We chose to sort the customers by Gross Margin percent in descending order (highest to lowes). This allows us to see the more profitable customers (even though they are below 20% GM) at the top on down to the least profitable. You can also select multiple sort criteria such as by salesperson, then customer name. You do not have to sort your results. If you do not, the results will be listed simply in the order that they are stored

Page 5 of 57

ANSWERS ODBC Seminar

in the file. In this case, the results would be in customer number sequence. Click on Next to continue when you have finished selecting your fields to use for sorting.

8.

The finishing options are presented. Select Return Data to Microsoft Excel and click on Finish.

9.

Microsoft Excel needs to know where to place the data. If you want the external data placed into the current worksheet, select Existing Worksheet. If you will be placing the data into the existing worksheet, you may wish to click on Properties and make sure that the options are set to not overwrite/erase any existing data on the spreadsheet. If you want the data to be placed on a new worksheet, click on New Worksheet. Click OK to have Excel import the data.

Page 6 of 57

ANSWERS ODBC Seminar

The data will be imported into the Excel spreadsheet. Excel normally defaults the column width to the width of the either the data itself or the width of the column heading, whichever is larger.

10.

Page 7 of 57

ANSWERS ODBC Seminar

11. For this reason, one of the most common things to do next if you plan on printing your report is to change the column headings to be more user-friendly. After the headings are changed, they can be easily resized in Excel to see more columns at one time. Once the data is in Excel, it can be manipulated just as any other spreadsheet. For example, we could add a column computed by an Excel formula to compare YTD totals to Last Year totals.

Page 8 of 57

ANSWERS ODBC Seminar

Example 2: Create a Summary Open Orders Report by Salesman

This example creates a summary listing of the open orders by salesman. In this example, we start with a single file, as in the other examples, however, we will then add an additional file to show the salesman’s name.

Answers Files: OEFMAST (Order Header File)ODBCSLSM (Salesman Names from Codes File)

1. Start a New Excel Document.2. From the menu bar, click on Data, then Import External Data, then New Database

Query. This will start Microsoft Query.

3. Select the data source that you wish to pull information from. Most users will have a database named “Answers Data”. Once you have selected your database, click on OK.

4. The available files in the data source will be displayed. Click on the + beside of the file(s) that you wish to use to see the actual fields available in each file. Always select the main file you wish to work from first. When you plan to add supplemental files for additional information, you can select their fields at this time as well, or wait

Page 9 of 57

ANSWERS ODBC Seminar

and add them later in “Edit Query” window of Microsoft Query. The initial selection should always be the main file from which the most records and data will come. This will make the query run faster. Click on OK.

5. Select the “columns” for the query. When data is pulled into an Excel spreadsheet, the columns of the spreadsheet will be the fields that you select to include. The rows of the spreadsheet will be the open order records that are selected to be included. from the open order file (OEFMAST). The columns of the spreadsheet will be ordered in left to right order, using the columns displayed in top to bottom order. However, it is important to note that you can rearrange the order of the fields by high-lighting a field on the right and then clicking on the up and down arrow buttons. Once you are satisfied with the fields you have selected and the order of them, click on Next to continue.

6. The Query Wizard next displays the filter data screen, allowing us to enter criteria for selecting the records that we wish to be returned. We want all the open orders in this case, so we are not going to filter the data, so we will just click on Next to continue.

Page 10 of 57

ANSWERS ODBC Seminar

7. Next, select the fields that you wish to sort by. In this example, we want to sort by salesman, warehouse, and order number so that we can eventually total by salesman.

8. Since we know that we need to add some additional information to the records, like the salesman name in this case, we need to edit the query in Microsoft Query. We can make our changes in Microsoft Query and then return the data to Excel for further editing later.

9. Once Microsoft Query is loaded, we will need to add an additional table (or additional file) in order to retrieve the salesman name. Click on TablesAdd Tables from the menu bar in Microsoft Query.

Page 11 of 57

ANSWERS ODBC Seminar

10. Select the table (file) that contains the data we want to add and then click on the “Add” button. In this case we want to add the “ODBCSLSM” table. Once you have added all desired files, click on the “Close” button. You will then see the file(s) added now shown beside your primary file. Once the files are shown, they can be resized and made wider to make it easier to read the field names. They can also be rearranged on the screen to make it easier to “link” the files together as explained in the next step.

11. Once the tables are added in Microsoft Query, we have to “link” the two files together. “Linking” the files together is the way that Microsoft Query recognizes the same data in each file. In this example, the Salesman number in the OEFMAST file is the same

Page 12 of 57

ANSWERS ODBC Seminar

as the Salesman number in the ODBCSLSM file. And, when the two numbers match, we want to get the Salesman name from the ODBCSLSM table. So, drag the mouse from the Salesman name in the OEFMAST table to the Salesman number in the ODBCSLSM table to create a “link” line between the two tables (files). This process in effect tells Microsoft Query how to take the salesman number on the open order file (OEFMAST) and find the proper salesman name from the codes file for salesmen (ODBCSLSM).

12. Now that the two tables are linked, we can insert a column to add the Salesman name to our query. Click on the Warehouse column (because this is the column we want to insert the new column before), and then click on Records, Insert Column from the menu bar.

13. In the Insert Column window, choose the field you wish to insert. You can also give it a column heading at this time. Click on “Insert” to add the field to your query. The field will immediately be added to your query as shown in the next screen. You can now add more fields, or click on “Close” to exit out of the Insert Column window.

Page 13 of 57

ANSWERS ODBC Seminar

14. The column is inserted and filled with the data. In this case, you should see the

salesman’s name for the corresponding salesman number listed in the new column.

15. Now, we can return the data to Excel to make further changes and get totals by salesman. To do this, click on the “door and arrow” icon and you will exit Microsoft Query and be returned to Microsoft Excel where you will be asked where you want to put the data (new sheet or existing sheet).

Page 14 of 57

ANSWERS ODBC Seminar

16. After the data is return and we “clean up” our column headings we will have the above information.

17. When working with orders, Answers stores all totals as positive numbers. So, when you deal with a return, you have to check the order/return flag to see if it is indeed a return, and then multiply by -1. We can add a simple formula in Excel to check for this and perform the proper calculation.

18. To do this, we need to use an IF evaluation:

IF this is a return THEN multiply the total by -1 ELSE (otherwise) use the total as it is.

Right-click on the entire “Status” column (by right-clicking its heading), then on “Insert”. This will insert a new column before the “Status” column where we will add our “formula” field.

19. Next, click in this new column and on the first line of actual data (not a heading line). Then click on Insert, then Function. You will see a list of functions supported by Excel.

Page 15 of 57

ANSWERS ODBC Seminar

20. In the selection list, choose IF, and then click on OK to continue entering the remaining information required for the “IF” function.

21. In the “Logical Test” box, enter the test we want to perform. You can either type in the test data, or you can click on the cell in the spreadsheet to be evaluated. Basically, we want to test the cell that contains the Order_Return_Flag to see if it is equal to an “R” (for returns).

Page 16 of 57

ANSWERS ODBC Seminar

22. If the test returns “true”, meaning that this is a return, we need to multiply the order total by a -1 so that our report shows a negative to clearly show the user that the line is a return instead of an order.

23. But, if the test is false, meaning that this is an order, we need to leave the order total as it is (meaning we don’t need to manipulate it in any way).

Page 17 of 57

ANSWERS ODBC Seminar

24. When you click OK, the formula is placed in the cell and then the calculated value is shown. You can copy the formula to the remaining cells (for other open orders) by right-clicking on the cell and selecting copy, then right-clicking on the column heading, and selecting paste. You can also drag the little plus sign at the bottom corner of the cell down to the end of the remaining cells containing data.

Page 18 of 57

ANSWERS ODBC Seminar

25. Since we now have a correct order total column, we can hide the first order total column and the order return flag, as we no longer need them to show. They were only needed to allow us to calculate a value for the real order total. So, we would not want to delete them, only to “hide” them. Deleting them would then mean the formula we just added would be referring to columns no longer available.

Page 19 of 57

ANSWERS ODBC Seminar

26. Since the spreadsheet is in Excel, we can insert rows between salesman and insert the total function (∑ on the toolbar) to calculate totals for each salesman. If desired, you can even copy each salesman to a different page. We can use Excel’s many features to make the total line bold, underlined, a different color, etc.

Page 20 of 57

ANSWERS ODBC Seminar

Loading Spooled Reports into an Excel Spreadsheet

At times you may find that the capabilities of ODBC are limited, or that your capabilities with Excel are limited. Or, you may find that an Answers report suits your need, if only it was in an Excel spreadsheet format. You can take many reports generated by Answers and create spreadsheets from them.

For example, take the Customer Price List Report. While a simple looking report, this report does a lot of work and calculations behind the scenes. It looks at information on the customer master, inventory master, contracts, and price exception files in determining what the actual price of an item is for a particular customer. If you utilize special pricing in Answers such as contracts and/or price exceptions, this report would be very difficult, if not impossible, to recreate from scratch in Excel. However, we could generate the report in Answers, and then load it into Excel in a situation where your customer demands you send them their prices in an Excel spreadsheet format.

1. First, print the desired report in Answers using the correct parameters, and then select the “View on Screen” option when you get ready to print it. Once the report is displayed on the screen in the Answers Report Viewer, exit from the report. You will be prompted to “Delete” the report file. In the window, asking you to delete it will be the report name in parenthesis. You need to make a note of this report name as you will need it later on. Be sure to answer NO to not delete the report, or otherwise it will not be available when you go to load it into Excel.

2. Start a new Excel spreadsheet. Open the file you made a note of in step 1. In this example, the file name is “CUSTPLW01.SPL”. These files are typically located in the datafiles directory on your server.

Page 21 of 57

ANSWERS ODBC Seminar

3. You may need to change the “Files of Type:” option to “All Files” to be able to see your datafiles once you browse into the datafiles folder.

4. When you click “Open”, Excel will automatically start the Text Import Wizard. It will not be able to recognize the file type. But, Excel knows you are not opening a spreadsheet file. It does not know how to create columns, so you will use the Text Import Wizard to establish columns for the spreadsheet.

Page 22 of 57

ANSWERS ODBC Seminar

5. The first step is to select the data type. Answers reports are fixed width which is the default setting. You can adjust the “start import at row” setting to automatically remove the first page headers. You will have to remove them manually from the other pages later. If it is handy for you to have the report headings, you may want to leave at least the first column headings in place for now. They can always be deleted later. Click on Next to continue.

6. On the next screen, you need to establish the columns. Excel tries to default column lines. To remove a column line, double-click on it, to add a column line, click in the space you want a column divider. You need to pay attention to your data for this part. It is normally best to set your column dividers at the beginning of each column. With numeric data this can be hard because you do not see exactly how long the data can be on the right. You will likely have to do some guessing. You can use the scroll bars to move down the page and see if the columns you have set make sense. Once you are happy with the columns, click Next to continue.

Page 23 of 57

ANSWERS ODBC Seminar

7. The final screen of the Text Import Wizard allows you to set the data types. Most data in Answers can be set to General or Text. On numeric data, you can click on the Advanced button to set thousands separators and decimals. Click Finish to create the spreadsheet.

Page 24 of 57

ANSWERS ODBC Seminar

8. Now your data is in a spreadsheet and can be manipulated as desired. You will need to remove page heading rows and adjust column sizes as necessary, depending upon what you are planning on doing with the data. A “cleaned up” version is shown below that could be sent to a customer asking for their prices in a spreadsheet.

Page 25 of 57

ANSWERS ODBC Seminar

Using ODBC with Microsoft Word

Example 1: Create Inventory Item Labels

This example creates inventory item labels that could be printed to code warehouse shelves or bins. The ideas presented here could be used to create any type of label, such as vendor or customer mailing labels. The main benefit to labels created through Microsoft Word is that the labels can be printed on a laser printer, with many different types of labels easily available.

ANSWERS File: INFMASTThis example uses the Inventory Master File (INFMAST).

1. Start a new document in Microsoft Word.

2. From the menu bar, select ToolsLetters and MailingsMail Merge. The exact menu steps may vary depending upon your version of Word, but should be similar. The Mail Merge Helper window is displayed.

3. Select Labels from the list of available document types, and then click on “Next” to go to step 2.

Page 26 of 57

ANSWERS ODBC Seminar

4. Select Use Current Document, and then click on Label Options to select the format of the label you are planning to use.

5. Find the type of label you have in the list of products and select it, and then click on “OK”. If you receive a warning that Word needs to delete the current contents of the document, click on “OK” as the document is still blank at this point.

Page 27 of 57

ANSWERS ODBC Seminar

6. Click on “Next” to go onto step 3.

7. From the Select Data Source window, click on ToolsMS Query to start Microsoft Query. We need to start Microsoft Query in order to retrieve the data for the labels from Answers files using ODBC.

8. From the Choose Data Source window, click on Answers Data on the Databases tab, and then on OK.

Page 28 of 57

ANSWERS ODBC Seminar

9. Scroll down the list of available tables and locate the Inventory Master File (INFMAST). Click on the + sign beside it to see a list of fields available from the selected file. Next begin selecting fields for your labels by clicking on the field name and then on the “>” button. Remember the order of the fields can be rearranged on the right by clicking on the field and then the up or down arrow buttons. When you have selected all fields, click on the Next button. Also keep in mind that you can select other fields to be included in you query in order to sort on them, or use them for filtering data in the next steps, without having to actually print them on the labels.

10. You now get a chance to select only certain inventory items using the “filter” options. For this exercise, we will only import items with an Aisle greater than or equal to “1A” and less than or equal to “1H”.

Page 29 of 57

ANSWERS ODBC Seminar

11. Next we get an opportunity to sort the inventory items based on how we want them to print out. We will sort them by Aisle and Bin for this example in ascending order (lowest to highest). Once you have selected all of your sort fields, click on “Next” to continue.

12. We don’t need to fine-tune the data any further in Microsoft Query for this example, so we

just tell it to Return Data to Microsoft Word and click on the Finish button.

Page 30 of 57

ANSWERS ODBC Seminar

13. We now are provided with a list of the items that that meet the filter selection options we choose earlier. Notice that the items are also sorted in the order we requested. However, you can still change the sort sequence of the items here by clicking on the headings at the top of a column. You can also deselect items from this list by un-checking the box to the far left. This will prevent the item from being imported into Word. Once you have made any desired changes, click on the OK button.

Page 31 of 57

ANSWERS ODBC Seminar

14. The items and the fields you chose are now available to Word, however we will have to tell Word which fields we want included on the labels, and in what arrangement. To do this click on “Next: Arrange your labels”.

15. Next, click on “More items…” to get a list of your fields from the ODBC file you selected. In this example, it will give us a list of the inventory fields we selected.

Page 32 of 57

ANSWERS ODBC Seminar

16. Click on each field in the order you want them printed, and then after each click the “Insert” button. After each time you insert a field, you will see that field’s place-holder code added to your first label. Once inserted into the document, the merge fields appear enclosed in << >> to distinguish them from regular text. Do not be concerned about the exact placement of the fields for now. Just insert them onto the label in the desired sequence. When you have inserted all desired fields onto the labels, click on the “Close” button. Note that the “Cancel” button changes to a “Close” button after one or more fields are inserted.

17. Now we can clean up the placement of the data fields on the label using the <Enter> key and normal Word manipulation. We use the <Enter> key in between fields to get 4 lines of data: stock number, description, aisle and bin, and overflow aisle and bin. We also use the space bar to put an extra space or two between the aisle and bin for legibility. You can also use this opportunity to change the font and size of the text on the label, just as you would change any other text in Word. For example, after reviewing the items in this example a few steps later, it was necessary to come back to this step (easily done using the “Back” links) and reduce the font size of the text from 10 to 9.

Page 33 of 57

ANSWERS ODBC Seminar

18. Now that we have our first label arranged to our satisfaction, click on the “Update all labels” button. This feature copies the arrangement and format (fonts, sizes, etc.) of the first label we have been working on to the other labels on the page. Depending upon the size of your screen, resolution settings, font sizes, etc. you may have to scroll down the “wizard/help” section of the screen to see this button.

Page 34 of 57

ANSWERS ODBC Seminar

19. This will populate all of the labels with the same field place-holder codes that we inserted onto the first label. Now, click on “Next: Preview your labels” to merge the data selected earlier with the layout of the labels. As was mentioned before with the “Update” button, you may have to scroll down the “wizard/help” section of the screen to see the “Next” option.

Page 35 of 57

ANSWERS ODBC Seminar

20. Review your labels to insure that you have got the records (inventory items in this case) that you want and that the layout of the data on each label (positioning, font, size, etc. is acceptable). You can even include or exclude additional records that you may have selected or unselected earlier by using the “Edit recipient list”. This is not normally necessary if you selected everything correctly the first time, but it is available here if needed. Once you are ready to finalize your merge, click on “Next: Complete the merge”. This will refresh the screen if necessary with any final changes you made to the recipient list (in this case, inventory items).

Page 36 of 57

ANSWERS ODBC Seminar

21. This is your final opportunity to make any changes or to go back to a previous step before

printing the labels. When you are convinced that you are ready to print the labels, insert the proper labels into the desired printer, and click on the “Print…” option.

22. Assuming you setup the proper selection criteria earlier in the query, you should be able to accept the default of “All” records at this prompt, and then click on “OK”.

Page 37 of 57

ANSWERS ODBC Seminar

Example 2: Create Credit/Collection Form Letters

This example creates a standard form letter for credit collection in Word. The mail merge feature is used to pull in customers who have at least a 90 day past due balance.

ANSWERS File: ARFCUSTFor this example we are using the Customer Master File (ARFCUST).

1. Start Microsoft Word to a new document. Type in the base of the letter, leaving a blank space at places where you plan to insert data from ANSWERS. For example, leave a place for the customer’s name, address, and balance. Any field available on the Customer Master File is available for use in ODBC. Some may not make logical sense to access through ODBC, but they would be available.

2. Since this is a form letter, you may wish to insert a Microsoft Word Field that will pick up the current date. This “field” will be inserted into the document at the position where the date should be. Then, each time the form letter is used, Word will automatically fill in the current date, instead of the user needing to change the date manually.

Position the cursor at the desired position for the date.

From the Word toolbar, click on InsertDate and Time. The Date and Time dialog window is displayed.

From this window, select the format of the date and time you want to use in this letter.

Also, make sure the “Update automatically” check-box is checked so the date will be updated each time this letter is accessed, otherwise today’s date will remain on the letter until changed.

Click on the OK button to have the date and time field inserted into your letter.

Page 38 of 57

ANSWERS ODBC Seminar

This will insert the current date in the format you selected. The field will be shown with a gray background to let you know that the information in the field will be updated automatically by Word.

3. Click on FileSave or FileSave As to save the document to save the work you have done thus far. We will save it again once we add the merge fields.

4. Once the document has been typed in you are ready to set up the data that will be used to fill in the form letter. Click on ToolsLetters and MailingsMail Merge from the Word menu bar. The Mail Merge Wizard is displayed down the right-hand side of the screen.

5. Insure that the wizard defaults to Letters, and then click on “Next: Starting document”.

Page 39 of 57

ANSWERS ODBC Seminar

6. Insure the wizard defaults to “Use the current document” and then click on “Next: Select recipients”.

Page 40 of 57

ANSWERS ODBC Seminar

7. Insure that the wizard defaults to “Use an existing list” and then click on “Browse…”. This is where you will tell Word where to get a list of recipients. In this case they will come through ODBC from the Answers Customer Master File.

Page 41 of 57

ANSWERS ODBC Seminar

8. From the Choose Data Source window, click on ToolsMS Query to start Microsoft Query. We need to start Microsoft Query in order to retrieve the data for the labels from Answers files using ODBC.

9. From the Choose Data Source window, click on Answers Data on the Databases tab, and then on OK.

10. Scroll down the list of available files and find the customer master file (ARFCUST). Click on the + sign beside the file name to see a list of available fields within the file. For this example, we selected the name, address, zip code, receivables contact, all of the ageing balances, last payment date, and last payment amount. To select a field, you can double-click on it on the left, or click on it, and then click on the > button. Any fields that you wish to sort by, or fields that you wish to use as criteria, should be selected, even if you do not plan to include them in the finished form letter. For example, if you wanted to sort by customer number, then you need to include the NUMBER field, even if you do not plan to print it out on the letter. Any fields that are not needed for printing, sorting, or for use as criteria do not need to be selected. Also, note that we did not select the Zip+4 code, just the standard 5-digit zip code. You may want to include the Zip+4 code, however, if you do, you will likely want to insert a dash “-“ in between the 5-digit code and the 4-digit code. But, keep in mind

Page 42 of 57

ANSWERS ODBC Seminar

that if you have a customer who does not have a Zip+4 code entered, Word will still print the dash (unlike Answers) so their zip code would end up printing as “25813-“.

11. When you have selected all fields that you need for your letter, click on the Next button.

12. This screen allows you to select the records that you want to include. Each customer in your Customer Master File is one record in ARFCUST. The filter screen allows you to select only the customers that you want to print a credit collection letter for. If you want to print the letter for all customers on file, simply click Next, without entering any criteria. For our example, we wanted to pick up customer’s who had a balance of at least $1000 over 90 days old. We clicked on the OVER_90_BALANCE amount. The criteria was placed on the right side and then we told the system to pick up all rows (records) where the customer’s OVER_90_BALANCE is greater than or equal to 1000. You will notice when you select a different field that the previously selected fields to limit records by are not shown on the right side any longer. This is normal. Word displays the fields that you have selected to limit records by in a bold font. You can see any criteria entered for that field by clicking on the field again. Click on Next once you have finished entering filter criteria. The Sort Order screen is displayed.

Page 43 of 57

ANSWERS ODBC Seminar

13. If you wish to have the credit letters sorted in a particular order, select the field to sort by. In our example, we sorted customers by the NAME field, so the letters would print out alphabetically. You can also choose whether the customer letters are printed in Ascending or Descending name order, but we are going to accept the default of ascending.

14. Two options are presented. Returning the data to Microsoft Word can be selected if you do not need to further edit the data being returned. The fields selected are returned as they are in the database. If you need to make any further record selections or edit the data, then you will want to return the records to Microsoft Query. One option is to use the Query Wizard to select all of the records, and then add the criteria by editing the data in Microsoft Query. In our example, we have already selected the criteria for the records we wish to be returned. However, we do want to edit the data, because we want to be able to print the customer’s total balance on the form letter. In ANSWERS, we store the Current Balance (how much is not past due yet), the Over 30 day balance, the Over 60 day balance, and the Over 90 day balance. But, we do not have a field already on the record with the total

Page 44 of 57

ANSWERS ODBC Seminar

balance. We need to calculate this field. So, we will select View data or edit query in Microsoft Query and then click on Finish. It may take a few minutes for the data to be returned from the customer master file onto your screen in Microsoft Query.

15. The Microsoft Query screen is divided into several areas. At the top of the screen, you will the table(s) or file(s) that have been selected. Microsoft Word refers to the files that you are using as tables. If you wanted to add another file (link two files together to retrieve data from both files), you could add another table here. The second area of the screen is the criteria. This is how the records are being selected from the files. The over 90 days selection criteria that we entered in the Query Wizard are shown. The third area of the screen is the actual records from your files. The records shown are the records that were retrieved from the customer master file based on the criteria that we entered. The data fields shown are the fields that we selected in the Query Wizard. The columns in the table are the data fields that we selected. Each customer record that met the criteria has a row in the table. New customer records could be added or removed by changing the criteria, new columns can be added by selecting additional data fields.

To insert a new column, scroll to the right side of the screen. This can be done by clicking on the arrow at the bottom right side of the screen. You will see a blank column as the last column. If you wanted to add a column containing information from the Customer Master File, click in the column heading portion of the blank column, then click on the arrow to view a list of available fields. Select the field that you wish to insert and Microsoft Query will retrieve the data for those fields.

We are going to add a new column that calculates the customer’s total balance. Click in the column heading portion of a blank column. The cursor will be blinking in the column heading. Type in the formula that you wish to use to calculate the data in

Page 45 of 57

ANSWERS ODBC Seminar

that column, using the actual database field names. It is very important to type the field names correctly in your formula, or you will receive an error. For our example, the formula typed in to calculate the total balance will be:

CURRENT_BALANCE + OVER_30_BALANCE + OVER_60_BALANCE + OVER_90_BALANCE

Once you have typed in the formula, press the <Enter> key. Microsoft Query will calculate the values for each customer record.

16. In order to use the customer’s total balance on the form letter, we need to give the column a name, double-click on the total balance column we just created. The edit column window is displayed. In the column heading field, type in a user-friendly name for the column. In the “Total” drop-down box, Word allows you to choose: Sum, Avg, Count, Min, and Max. For our example, we want a Sum of the listed fields.

Once the data has been selected and the columns set you are ready to return the data to Microsoft Word. From the File menu in Microsoft Query, select Return Data to Microsoft Word.

17. We are now ready to click on “Next: Write your letter”.

Page 46 of 57

ANSWERS ODBC Seminar

18. We are now ready to begin inserting the mail merge fields into our document. These are the fields that will change from letter to letter depending upon the customer. Insert each field by doing the following:

Position the cursor at the location within the letter where a mail-merge field should be placed.

Click on “More items…” in the wizard/help pane of the window. This will give us a list of the fields from our ODBC query that we have been working on.

Page 47 of 57

ANSWERS ODBC Seminar

Click on the field you want to insert, and then click on the Insert button and then on the Close button. You can also insert multiple merge fields at one time before clicking the close button, but then you will have to reposition the merge fields within the document using normal text manipulation such as the <Enter> key to move an address line to the next line. This is especially handy in an example where you insert the 3rd address line followed by the zip code. All that needs to be done in the document is to then place a space between the address line and zip code.

The fields are inserted onto the document. Each merge field is displayed with a gray background when you click on them and with angle brackets << >> surrounding the field name. This makes it easy to see where your merge fields are located.

Move your cursor to the next merge field you want to insert and then repeat these steps.

Page 48 of 57

ANSWERS ODBC Seminar

19. At this point, it is usually a good idea to save the document again. When we create the form letters, we will be using this document as the source and creating a new document containing the merged letters. This will preserve the source document for re-use at a later time. After we have saved our source document, click on “Next: Preview your letters”.

20. Formatting the Data Fields – If you click on “Preview your letters” at this time, you will notice that the amount fields (current, 30, 60, 90, total balance, and last payment amount) don’t always print in a consistent format or a format that is very “user-friendly”. Sometimes a numeric field may have several extra digits after the decimal point, or sometimes it may not have a decimal point at all. You may also have issues with upper-case and lower-case letters on names and addresses. It would be nice to format these fields to print out in a more “user-friendly” format. This can be done by entering Word format commands into our source document for mail-merge codes. It is important to remember that these are not required, but are useful in making your letter look more professional.

If you did jump ahead and use the “Preview” option, be sure to back up to your original source letter using the “Previous” link.

Right-click on the field you would like to format better and click on “Toggle Field Codes”. This will show the actual field codes being used by Microsoft Word in your document.

For example, we could format the contact name field to only capitalize the first letter of each name, where you might have entered it into the customer with all upper-case letters. The same thing could be done to customer names and addresses, but use caution as this does not work well on state abbreviations.

Page 49 of 57

ANSWERS ODBC Seminar

Word provides 4 different methods for capitalization.

Capitalize the first letter of each word.Capitalize the first letter of the first word.Capitalize all letters of all words.Capitalize no letters of any words.

For our example, we will use the option to capitalize the first letter of each word. The format you choose to use needs to be based on how you wish your form letter to print this particular field. Once “Field Codes” are toggled on the merge-field for the contact will show as:

{ MERGEFIELD “arfcustRECEIVABLES_CONTACT” }

By adding additional Word formatting codes, the merge field will appear as in order to get the first letter of each word capitalized:

{ MERGEFIELD “arfcustRECEIVABLES_CONTACT” \* Caps }

As mentioned earlier, we can also format the numeric fields that will be printing the amounts to make them more “user-friendly”. Using additional Word formatting codes, we can specify the number of digits to be printed in each number, how negative amounts should be printed, and whether we wish to print a dollar sign or not. It is recommended that you only enter the number of digits that you think that you will really need, since Word will leave a space if a digit is specified but not needed.

For example, the merge field for the TOTAL_BALANCE appears as:

{ MERGEFIELD “TOTAL_BALANCE” }

Using the Word formatting codes, change it to read:

{ MERGEFIELD “TOTAL_BALANCE” \# “###,###.00” }

This tells the system to allow for and print numeric values as 999,999.99. If you wanted to include a dollar sign at the beginning of the number, you would enter:

{ MERGEFIELD “TOTAL_BALANCE” \# “$###,###.00” }

Unfortunately, Word does leave blank spaces in between the dollar sign and the first digit, which is not the optimal format, but if you want the dollar sign to be printed, you may be willing to accept this.

You will likely also want to apply these formatting codes to all of the numeric fields (current, 30, 60, 90, and last payment amount).

A revised copy of the original letter showing all of our formatted fields is shown below.

Page 50 of 57

ANSWERS ODBC Seminar

21. Now, we are ready to try again to merge the source form letter with the actual data from ANSWERS. Click on the “Next: Preview your letters” link. You will then be taken to a letter for the first customer meeting your selection criteria (over $1000 90 days old).

Page 51 of 57

ANSWERS ODBC Seminar

22. You can review the format of your letter once again to make sure you are satisfied with your re-formatted fields from the previous step (if you elected to do so). You can also click on the << and >> buttons to scroll through letters generated for each recipient meeting your selection criteria. When you are ready to proceed, click on the “Next: Complete the merge” link.

Page 52 of 57

ANSWERS ODBC Seminar

23. From here, you can either Print your documents, or Edit individual letters. If you choose to print your documents now, you will be given an option as to which records to print.

You will likely want all of your records to print, which is the default, so just click on “OK”. You will then be prompted for the printer on which to print your letters. Once the printer is selected, your merged letters will be printed completing this process

If you chose to edit your letters, then Word will create a new document containing the results of the merge. This will allow you to make changes or additions to individual letters. Similar to printing, you will be given one last chance to choose which records to merge.

Page 53 of 57

ANSWERS ODBC Seminar

Assuming you want all customers selected merged into your new document (which can then be later edited or printed), you will want to insure that the default of “All” is selected and then click on “OK”.

You will now have a new document on your screen containing all letters resulting from your merge. You would then proceed to review and make any desired changes or additions to individual letters. Once those are complete, you would then print the letters from this document.

If you later decided to re-do the merge, you would want to exit out of this newly created document and return to your original and instruct it to either print the merged letters or re-create a new document once again.

24. Regardless of what you decide to do in your final step, be sure to Save your original document when you leave Microsoft Word, especially if you have made any changes that affect the source document. Remember that if you created a new document with your merged letters, that the form letters are contained in a separate document. If you want to

Page 54 of 57

ANSWERS ODBC Seminar

also save the merged letters, then be sure to use a name different than the name of the original source document.

Performing the Merge at a Later Time

Once you save the merge source document, you can perform the same mail merge at any time in the future.

1. Start by bringing up your source document in Microsoft Word. Word has saved the mail merge database information along with the document. It does not save the actual data, just the link information needed to connect to the data. Therefore you may get a prompt similar to the following when accessing the source document.

2. This prompt is just informing you that this document contains commands to access your data and pull in the necessary fields. It is safe to Answers “Yes” to this prompt. Once you do so, you will see a copy of your letter, already showing data from the first customer meeting the selection criteria we established earlier in this project.

Page 55 of 57

ANSWERS ODBC Seminar

3. Once again, we will click on ToolsLetters and MailingMail Merge. Notice this time that the merge wizard will start at step 3 instead of step 1. We can make changes along the way, or simply keep advancing to the next step to print our merged letters.

Page 56 of 57

ANSWERS ODBC Seminar

4. If we want to change any of the information that the letter is retrieving, or if we want to change any of the selection criteria, then we would want to click on “Select a different recipient list”. If we wanted to review the recipient list and make any desired deletions, we would click on “Edit recipient list”. When we are ready to continue with a new merge, we would click on “Next: Write your letter” (which we have already done, but we will get a chance to make any changes to the letter if desired).

5. Make any desired changes to the source letter including any formatting changes we discussed earlier pertaining to merged data fields. When you are ready to continue, click on “Next: Preview your letters”. By now these steps should be familiar.

6. You can then review your recipient’s letters once again, scrolling back and forth amongst them, and even excluding letters for selected recipients. To finish the merge, click on “Next: Complete the merge”.

7. Finally, either Print your letters or create a new document containing the merged letters by clicking on the “Edit individual letters” link.

Page 57 of 57