47
ANSWERS ODBC Seminar Copyright 2004 Data Resources Corporation Page 1 of 47

Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

  • Upload
    lamdat

  • View
    216

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

Copyright 2004Data Resources Corporation

Page 1 of 38

Page 2: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

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 capable programs, such as Microsoft Word and Microsoft Excel, 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 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 38

Page 3: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

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.

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

1. Start a new document in Microsoft Word.

2. From the menu bar, select Tools, then Mail Merge. The Mail Merge Helper window is displayed.

3. Click on the Create button to create a new mail merge.

4. Select Mailing Labels from the list of available options to create.

5. Select Active Window to use the current new document, or New Main Document to create a new Word Document.

Page 3 of 38

Page 4: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

6. Click on Get Data and select Create Data Source.

7. This part of the program would allow you to create your own database records to be used in a mail merge. This would be done by typing in the values that you wanted to use. Since, we want to pull in the data through ODBC, we will click on the MS Query option.

8. Select the data source that you want to pull the information from and click on OK. This will normally be a data source set up to pull information from ANSWERS data.

Page 4 of 38

Page 5: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

9. Once you have selected the data source, the various “tables” available in that data source will be displayed. In ODBC, a “table” relates to the ANSWERS file. A “column” relates to the fields in the file. The files, or “tables”, are listed. Click on the + beside of the filename to display the fields. The fields you select to include will become the “columns” used by Microsoft Query. The fields selected will be the fields that you may print on the labels. Any fields that you wish to print. sort, or enter selection criteria on need to be included. To add a field click “>”. To remove a field click “<”. To remove all fields click on “<<”. For example, we are not going to print the “Discontinued Flag”, but we need it for filtering out the items that we want to print labels for.

10. Once you select the fields to include in the query, you will select the fields that will be used to filter the data. This is where you enter any specific selection criteria to only pick up certain inventory items. In ANSWERS, the Inventory Master File can contain normal stock items, discontinued items (items that will be deleted once all quantities are down to zero), and non-stock items. The DISCONTINUED_FLAG contains the status of the items. In this example, we only want to print labels for stock items, excluding any items where the DISCONTINUED_FLAG is “N” (non-stock) or “D” (discontinued).

Page 5 of 38

Page 6: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

11. Next, we will select how the items are sorted. This example chose to sort items by Warehouse and then by Stock Number. We could just as easily have sorted the items by aisle and bin or any other field on the Inventory Master File.

12. Once the filter and sort options have been completed, the Finish options are presented. We can choose the edit the data further in Microsoft Query, or to simply return the data to Microsoft Word. For this example, we chose to Return Data to Microsoft Word.

13. Since we have not yet defined the main document where we will insert the merge fields, Word will give us the option to Set Up Main Document.

Page 6 of 38

Page 7: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

14. Since we told Microsoft Word that we wanted to do mailing labels, the program will now prompt us to enter the label information. First, select the printer that you wish to print the labels on. A list of labels that fits that printer will then be available. The most common types of labels are Avery, but there are several other brands of labels available. Click on the arrow beside of Label Products to choose the label you are using. Match up the labels with the label number printed on the box. This will insure that you have the right labels. Word will allow you to enter as many lines as will fit on the label that you choose.

You can also click on the Details button to preview the label size and the number of labels across the page and the number of labels down the page.

15. Once you have finished selecting the labels, click on OK and Word will prompt you for the information to be printed on each label.

Page 7 of 38

Page 8: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

16. Type in any text that you want to appear on each label. You can insert a merge field to print data from the ANSWERS files, by clicking on Insert Merge Field. A list of the fields that you selected earlier in the Query Wizard are displayed. Once inserted into the document, the merge fields appear enclosed in << >> to distinguish them from regular text.

17. Once you have finished setting up the labels, click OK and the Word will create the pages of mailing labels.

Page 8 of 38

Page 9: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

On screen you will not see the outlines for the labels, but they will be printed correctly in the right place for the label design that you have chosen.

Page 9 of 38

Page 10: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

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 60 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, the customer’s name, address, and balance. Any field available on the Customer Master File is available for use in ODBC.

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 Insert, then Field. The Field category box is displayed.

Highlight Date and Time in the Categories list, then highlight Date in the Field names list. Click on OK.

This will insert the current date in the format mm/dd/yy. The field will be shown with a gray background. This is a designation that the information is a field that Word will fill in automatically. Later in these instructions you will see how you can use Word formatting commands to format the appearance of the date.

3. Click on the to save the document. This saves the work you have done so far. We will save it again once we add the merge fields.

Page 10 of 38

Page 11: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

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 letters.

Click on Tools, then Mail Merge from the Word menu. The Mail Merge Wizard is displayed.

Click on the Create button to set up the mail merge database information.

The Create menu has four options. We are creating Form Letters. This allows Word to know that there could be more than one letter generated from the source document.

Mail merge provides two options, Active Window or New Main Document. Since we want to use the letter just typed in as our source document for the form letters, we will select Active Window. The Mail Merge Helper window will now display the type of mail merge we are performing, and the source document name.

Page 11 of 38

Page 12: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

Now we are ready to set up the database file from which the merge information will be pulled from. Click on Get Data, then Create Data Source. The Create Data Source window is displayed.

Click on MS Query, since we want to use the Microsoft Query to extract information through ODBC. Microsoft Query will be started, and the list of available databases displayed.

Highlight the Data Source Name that points to the ANSWERS data files. Then, click on OK.

Please wait while Microsoft Query connects to the selected database and builds a list of available files. This may take a few minutes.

Page 12 of 38

Page 13: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

Once the available list of files is displayed, click on the + beside of the file you wish to use to display the list of fields. From the list of fields, click on all fields that you will need to use in the query. 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 needed for printing, sorting, or for use as criteria do not need to be selected.

Click on Next. The Filter Data screen is presented.

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.

Page 13 of 38

Page 14: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

For our example, we wanted to pick up customer’s who had a balance at least sixty days old. We clicked on the OVER_60_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_60_BALANCE is greater than 0.00. Then, because we want to include all customers who are at least 60 days past due, we also need to check the 90 days past due amount. It is possible for a customer to have a 0.00 60 days amount, but to have a 90 days past due amount. Any customer’s in this category should also be sent a credit letter. So, the same exact criteria was added for the OVER_90_BALANCE field. The or criteria type was used. Now, any customers who have an “OVER_90_BALANCE greater than 0.00” or an “OVER_90_BALANCE greater than 0.00” will be included for a credit letter. 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 the criteria. The Sort Order screen is displayed.

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 order.

Page 14 of 38

Page 15: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

Click on Next and the Finish options are presented.

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 balance. We need to calculate this field. So, we will select View data or edit query in Microsoft Query.

It will take a few minutes for the data to be returned to the Microsoft Query screen.

Page 15 of 38

Page 16: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

The screen is divided into several areas. At the top of the screen, you will the table(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 would add another table.

The second area of the screen is the criteria. This how the records are being selected from the files. The two criteria that we entered in the Query Wizard are shown. We will add additional criteria to the form letters later.

The third area of the screen is the records. 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 the 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.

Page 16 of 38

Page 17: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

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 that column, using the actual database field names. 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.

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 column we just created. The edit column window is displayed.

Enter a name for the column, and then select the type of function being performed. 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, select Return Data to Microsoft Word. Since we have not yet entered any merge fields on our form letter, the following window might be displayed:

Click on Edit Main Document to insert the merge data fields.

5. Now that we have selected a list of data fields to be used, we are ready to insert the fields in the form letter document. You should notice that two new toolbar options have been added. These options are located in the upper left corner, beneath Word’s normal toolbar. One option says Insert Merge Field and the other option says Insert Word Field.

Page 17 of 38

Page 18: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

6. Position the cursor at the first location where a merge field should be placed. Then, click on the Insert Merge Field option. A list of the fields that we selected to include in our query will be displayed. Select the desired field by clicking on it. The fields are inserted onto the document. Each merge field is displayed with a gray background and << >> surrounding the field name. This makes it easy to see where your merge fields are located. Continue inserting merge fields until you have completed your document.

7. 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 merge letters. This will preserve the source document for use at a later time.

8. Now, we are ready to merge the source form letter with the actual data from ANSWERS. From the menu, select Tools, then Mail Merge. The Mail Merge Helper window is displayed again. Click on Merge. The Merge options window is displayed.

9. Select New Document as the “Merge to” document. This will create a new Word document containing all of the form letters. You also have the option to print blank lines when a data field is empty or to not print the blank lines. Click on Merge and Word will create a new document containing your form letters, with all of the appropriate data fields filled in, using data from the ANSWERS Customer Master File. In this particular merge, you will only get form letters for customers who have either a sixty day past due balance, or a ninety day past due balance.

10. Save your original document when you leave Microsoft Word, especially if you have made any changes that affect the source document. The form letters are contained in a separate document. You may save these if desired, using a document name separate from your source document name.

Performing the Merge at a Later Time

Once you save the merge source document, you can perform the mail merge at any time. Bring 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.

After the document is opened in Word, you can click on Tools, then Mail Merge from the menu. Then, click on Merge in the Mail Merge Helper window to create the form letters.

Page 18 of 38

Page 19: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

Modifying the Mail Merge

The mail merge criteria and fields included can always be modified at a later time. In our example, we created form letters for each customer that had a balance that was over sixty days or over ninety days past due. But, we could also only pick up customer’s with a certain business type, if we only wanted to send credit collection letters to our retail customers, or any other specific business type.

Open the source document in Microsoft Word.

From the menu, select Tools, then Mail Merge. The Mail Merge Helper window is displayed.

Click on Edit, then ARFCUST to make changes to the data being retrieved from the Customer Master File.

Microsoft Word will start Microsoft Query and connect the database. Once Microsoft Query is displayed, if you cannot see the ARFCUST table, you can click on Edit, then View Tables from the file menu. If you cannot see the criteria, you can click on Edit, then View Criteria.

To add a new criteria, click on Criteria, then Add Criteria from the file menu. The Add Criteria data box is displayed.

Select whether you are performing a “And” result or an “Or” result. Let’s look at the difference. We already have criteria that states “Pick up any customer with an OVER_60_BALANCE greater than 0 or an OVER_90_BALANCE greater than 0”. Now, we want to add criteria for the BUSINESS_TYPE. If we use “OR”, then we area saying “Pick up any customer who has a sixty day or ninety day past due balance or who has a business type matching our BUSINESS_TYPE criteria”. In this case, we may get credit collection letters for current customers, simply because the business type criteria matches. This is true of an OR criteria type. If either part of the criteria matches, then the record is chosen. In this same example, if we choose the “and” option, then we are saying, “select records where the OVER_60_BALANCE is greater than zero or the OVER_90_BALANCE is greater than zero and the business type matches our criteria”. In this example, we get only customer’s who match both sides of the criteria. They have sixty or ninety day past due balances, and they are of a selected business type(s). This is true of any AND selection, records must match both parts of the criteria before they are chosen.

Select the Field you want to add criteria for.

Page 19 of 38

Page 20: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

Select the Operator. There are several operators to choose from. You can select only records where the business type matches one particular business type value, or you can select a group of business types, where the customer records needs to match one of the selected. You can also choose to select records that do not match a particular business type, ie. as long as the business type is not equal to a particular value, it will be chosen.

You may key in the value(s) for the business type field, you can click on the Values button to have Microsoft Query provide a list of values from the customer master file.

To select multiple values, simply click on all of the values that you want to use as criteria.

Once you have finished defining the Criteria, click on Add to insert the criteria. You can see immediately how your criteria affects the records that are being selected from the data source. Click on Close the close the criteria window.

From the File menu, select Return Data to Microsoft Word to exit from Microsoft Query, back to Word.

Be sure to save the source document so that your query changes will be saved.

Formatting the Data Fields

In our example document that we have created, the date fields are shown as mm/dd/yy fields. And, the total balance that we calculated has several extra digits after the decimal point. It would be nice to format these fields to print out in a more “letter quality” format. This can be done by entering Word format commands into our source document.

Bring up the source document in Microsoft Word. From the Tools menu, select Options. Then, on the View tab of the Options box, place a checkmark in the Field Codes option. This will show the actual field codes being used by Microsoft Word in your document. Position the cursor at the end of the first field that you wish to form. For example, the letter date field. By default, the field code for the date should be:

{ DATE \* MERGEFORMAT }

This code formats the date as mm/dd/yy and preserves this format each time you perform a mail merge. We want to change the format from mm/dd/yy to the more professional date of month day, year. We have to leave the word DATE, because this instructs Word to insert the current date. Using the Microsoft Word format codes, change the format to be:

Page 20 of 38

Page 21: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

{ DATE \@ “MMMM d, yyyy” \* MERGEFORMAT }

According to the codes list, the @ sign represents date formatting codes. The MMMM will print the full name of the month, the d will print the day of the month, without leading zeroes, and the yyyy will print the four digit year. The comma instructs word to place a comma between the day and the year.

We can format all of the dates in the document in this manner.

Next, we can format our name and address fields. Most users have their names keyed into ANSWERS using all capital letters. 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 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 appear.

The merge field for the contact person is shown as:

{ MERGEFIELD RECEIVABLES_CONTACT }

By adding Word format codes, the merge field will appear as:

{ MERGEFIELD RECEIVABLES_CONTACT \* Caps}

We can also format the numeric fields that will be printing the amounts. Using the Word format 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 do use only the number of digits that you think that you will need, since Word will leave a space if a digit is specified but not used.

The merge field for the TOTAL_BALANCE appears as:

{ MERGEFIELD TOTAL_BALANCE }

Using the Word format codes, it becomes:

{ 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” }

Just keep in mind that spaces are left between the dollar sign and any numbers that you do not use. One last note on the form letter. Many times the four digit zip code is only used if necessary. Some users may make a judgment not to include the four digit portion any time, while other users may wish to include the four digit portion, if it is there. Either way is fine, but you may end up with addresses showing:

99999-

Page 21 of 38

Page 22: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

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 Get External Data, then New Database Query. This will start Microsoft Query.

3. Select the data source that you wish to pull information from. 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. Select the “columns” for the query. When data is pulled into an Excel spreadsheet, the columns

Page 22 of 38

Page 23: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

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. Click on Next to continue.

5. 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 Month to Date 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.

6. Next, select the field that you wish to sort the customers by. We chose to sort the customers by Gross Margin percent. This way, we can see of the customer’s who are below 20% gross margin, who are the highest profitable customers. Click on Next to continue.

Page 23 of 38

Page 24: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

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

8. 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 24 of 38

Page 25: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

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. Once the data is in Excel, it can be manipulated just as any other spreadsheet.

We can also add additional columns if we wanted compare the YTD totals to Last YTD totals.

Page 25 of 38

Page 26: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

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 two additional files to show the salesman’s name and the customer’s name.

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

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

Query. This will start Microsoft Query.

3. Select the data source that you wish to pull information from. Always select the main file you wish to work from. When you plan to add supplemental files for additional information, they will be added later in the “Edit Query” window. The initial selection should always be the main file from which the most records will come. This will make the query run faster. Click on OK.

Page 26 of 38

Page 27: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

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. 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. Click on Next to continue.

5. 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. Once you have finished entering your criteria, click Next to continue.

Page 27 of 38

Page 28: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

6. Next, select the fields that you wish to sort by. In this example, we want to sort by salesman so that we can eventually total by salesman. We could also choose to sort by customer if desired.

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

8. Once Microsoft Query is loaded, we will need to add additional tables, or additional files in order to retrieve the salesman name. Click on Tables, then Add Tables.

Page 28 of 38

Page 29: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

9. Select the table (file) that contains the data we want to add. In this case, ODBCSLSM. Once the table is shown 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 as the Salesman number in the ODBCSLSM file. And, when the two numbers match, we want to use the Saleman name. So, drag the mouse from the Salesman name on OEFMAST table to the Salesman name on the ODBCSLSM file to create a “link” line between the two tables (files).

10. 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, then click on Records, Insert Column. In the Insert Column window, choose the column you wish to insert.

Page 29 of 38

Page 30: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

11. The column is inserted and filled with the data.

12. We can add the ARFCUST table in the same manner, linking the OE_DEALER field to the Customer Number field and inserting a column for the customer name.

Page 30 of 38

Page 31: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

13. Now, we can return the data to Excel to make further changes and get totals by salesman.

14. 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 formula to Excel to check this and perform the proper calculation.

15. 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.

Click on the first line of data (not a heading line) in a blank column. Then click on Insert, then Function. In the selection list, choose IF. Click on OK to continue entering your function.

Page 31 of 38

Page 32: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

16. 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 “R”.

Page 32 of 38

Page 33: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

17. If the test returns “true”, meaning that this is a return, we need to multiply the order total by a -1.

18. But, if the test is false, meaning that this is an order, we need to leave the order total as it is.

19. 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 by clicking on the cell and selecting copy, then dragging the little plus sign at the bottom corner of the cell down to the end of the remaining cells.

Page 33 of 38

Page 34: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

20. Since we have a correct order total column, we can hide the first order total column and the order return flag. They were only needed to allow us to get calculated values for the real order total.

21. Now that 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.

Page 34 of 38

Page 35: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

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 reports generated by Answers and create spreadsheets from them.

1. First, print the report in Answers using the correct parameters, and the “View on Screen” option. Once the report is displayed, exit from the report. You will be asked to “Delete” the report file. In the window, asking you to delete, will be the report name in parenthesis. You need to make a note of this report name. Answer NO to delete.

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

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

Page 35 of 38

Page 36: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

4. When you click “Open”, Excel will automatically start the File Import Wizard. It does not 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 File Import Wizard to establish columns for the spreadsheet.

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

Page 36 of 38

Page 37: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

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 have to use your best estimate. 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.

7. The final screen of the File 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 37 of 38

Page 38: Using ODBC with Microsoft Word - drcanswers.com€¦  · Web viewStart a new document in Microsoft Word. From the menu bar, select . Tools, then . ... Start Microsoft Excel and begin

ANSWERS ODBC Seminar

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.

Page 38 of 38