Sie sind auf Seite 1von 32

14 Import and Export Data

LESSON SKILL MATRIX


Skill Importing Data Exam Objective Import source data into a new table. Append records to an existing table. Import data as a linked table. Objective Number 2.5.1 2.5.2 2.5.3 Saving and Running Import Specications Exporting Data ort Specications Saving and Running Export Specications

KEY TERMS
delimited le delimiter xed-width le linked table specication

350
Copyright 2012 John Wiley & Sons

Import and Export Data

351

You are Yo ar You ar the human resources coordinator at Humongous Insurance, a private com company dedicated to offering products that provide quality protection with va value pricing for rural and low-income families, as well as senior citizens on x xed incomes. Your department has just begun to use Access, but you still x rec receive data in different formats that must be merged with your Access da databases. At times, you also want to distribute information that your manag prefers to view in a different format. In this lesson, you learn how to ager im imp import data, link to an external data source, and save and run import specications. You also learn how to export data from a table and from a query, as well as how to save and run export specications.

SOFTWARE ORIENTATION IENTATION


External External Data Tab ern Ta Tab
The External The External Data tab contains commands that will be used to import and export data in h contains commands ai i be used impo various formats. Use Figure 14-1 as a reference throughout this lesso as well as the rest of 14-1 lesson vari va ious 1 throughout ho hout this book. this ook this book.
Figure 14-1 e External Data tab ta View View and run i the he h the import operations you operations pe previously saved previously View and run the export export View ew e p operations you previously saved previously o rat operations i s

IMPORTING DATA IMPORTING DATA ORT A A


The Bottom Line ne

To store data from an external source in Access, you can import the d into a new or existing a from an m n Access, cces cc s data database. After you run an import operation, you can save the imp settings for reuse. You import run an import ope u por operation, per mainta can also link to data from an external source without actually maintaining a copy of the data in h d b the database.

Importing Data from a Specic Source


You can import data from a variety of sources into an Access database. When you import data, Access creates a copy of the data in a new or existing table without altering the source le. Before you start the import operation, decide whether you want to store the data in a new or existing table. If you choose to store the data in a new table, Access creates a table and adds the imported data to this table. If a table with the specied name already exists, Access overwrites the contents of the table with the imported data. If you choose to add the data to an existing table, the rows in the Excel le are appended to the specied table. In this exercise, you import data from an Excel worksheet into a new Access table. You can also import data from other specic sources besides Excel, such as a SharePoint list, a Word le, another Access database, or a text le. The same general process is used for importing data, regardless of the source. On the External Data tab, in the Import & Link group, click the More button to see additional formats that you can import from or link to.
Copyright 2012 John Wiley & Sons

352

Lesson 14 Take Note

You can import only one worksheet at a time during an import operation. To import data from multiple worksheets, repeat the import operation for each worksheet. Before you import, you should always review the source data and make any necessary modications, as described in Table 14-1.

Table 14-1 Source Data Elements

Element Number of columns Skipping columns and rows

Description You cannot import more than 255 source columns, because Access does not support more than 255 elds in a table. It is a good practice to include only the rows and columns that you want to import into the source worksheet or named range. Note that you cannot lter or skip rows during the import operation. If you choose to add the data to an existing table, then you cannot skip columns during the operation either. g p Ensure that the cells are in tabular format. If the worksheet or named range nc ud rang includes merged range inclludes merged cells, the contents of the cell are placed in the nge ud eg eld that corresponds to the leftmost column, and the other elds corresponds to on onds a are left blank. are left blank. l Delete all unnecessary blank columns and blank rows in the Dele e Delete Delete k collumns worksheet work wo wo ksheet or range. If the worksheet or range contains blank cells, wor ksheet rk h try o tr y to add the missing data. If you are planning to append the records r you are o t t to an existing table, ensure that the corresponding eld in the table existing a existing table, ensure that th correspond isti s su sure hat th accepts null (missing unknown) values. accept null (missing or unknown) values. A eld will accept null pts pt nu m n o a el values t v e if its values if its Required eld property is set to No and its ValidationRule d property s ro t r property setting does not prevent nulll values. t ty no not prevent null t If If one or more cells in the worksheet or range contain error values, o n he worksheet h e such # such #NUM d #DIV, su as #NUM and #DIV, correct them before you start the import D them e operation. If a source worksheet or range conta error values, operat ation. If source worksheet or range contains at at rc a Access places null value Access places a null value in the corresponding elds in the table. s l nu corresponding o e To avoid errors during To avoid errors during importing,, ensure that each source column v ro o u ens nsure ns ns e contains contains the same type of data in every row. It is a good practice to o a same am m n every v format format each source column in Excell and assign a specic data format o a Exce xce to each column before you start the import operation, especially if a o each c star t the ar a op column colum co mn includes values of different data types. o different ff ff re If the If the rst row in the worksheet or named range contains the names th wor ksheet or k rang you can of the columns, you can specify that Access treat the data in the y ca an trea rst row as eld names during the import operation. If your source rst row as eld names d oper worksheet worksheet or range does not include the names, it is a good idea kh name to add them to the source before you start the import operation. Note: If you plan to append the data to an existing table, ensure that the name of each column exactly matches the name of the corresponding eld. If the name of a column is different from the name of the corresponding eld in the table, the import operation will fail. To see the names of the elds, open the table in Design View in Access.

Tabular format

Blank columns, rows, and cellls columns, ol nd ells nd cells

Error values Error r r

Data type Data type t y

First row

Troubleshooting The worksheet should be closed before beginning the import operation. Keeping the
source le open can result in data conversion errors.

Copyright 2012 John Wiley & Sons

Import and Export Data

353

Troubleshooting After an import operation, you should review the contents and structure of the table
to ensure that everything looks correct before you start using the table. If you see the message An error occurred trying to import le, the import operation failed. If the data imports and you nd just a few missing values, you can add them directly to the table. However, if you nd that entire columns or a large number of values are either missing or were not imported properly, use Access Help to troubleshoot the results and correct the problem in the source le. After you have corrected all known problems, repeat the import operation.

STEP BY STEP

Import Data from Excel


GET READY. Before you begin these steps, be sure to LAUNCH Microsoft Access.

The Humongous le for this lesson is available on the book k companion website or in WileyPLUS.

1. OPEN the Humongous database from the data les for this lesson. 2. SAVE the database as Humongous XXX (where XXX is your initials). X X in 3. On the External Data tab in the Import & Link group, click Excel. The Get External Data tab, n the Data ab, he Exce DataExcel Spreadsheet dialog box appears, as shown in Figure 14-2. DataExcel Spreadsheet dialog box app xce preadsheet dial g c dshe e l ppears, Fig

Figure 14-2 e Get External DataExcel Excel Spreadsheet dialog box og


Click to locate source file

The New_Employees le for this lesson is available on the book companion website or in WileyPLUS.

4. Click Browse to open the File Open dialog box. 5. Use the Look in box to locate the New_Employees spreadsheet le and then click Open. 6. Notice the three options you have when importing data. Click Import the source data into a new table in the current database and click OK. The Import Spreadsheet Wizard appears, as shown in Figure 14-3.

Copyright 2012 John Wiley & Sons

354

Lesson 14
Figure 14-3

Import Spreadsheet Wizard, screen 1

Take Note

On the rst screen of the Import Spreadsheet Wizard, Access also allows y to append a copy he e S Spreadsheet Access also s you of the records to an existing table in the database. Choose Append a copy of the records to the table he records to existing tabl e e ords sting table t n able he database. Choose Append ataba tab hoose ppe o and then select an available table from the drop-down list. then el t the select available table from the drop-down list. ble ab b m the h l t
7. Click Next > to display the next screen, as shown in Figure 14-4. Click l xt to t the h screen, shown Figure w u

Figure 14-4 4 Import Spreadsheet Wizard, , screen 2

8. Click the First Row Contains Column Headings check box. Access uses these column headings to name the elds in the table.

Copyright 2012 John Wiley & Sons

Import and Export Data


9. Click Next > to display the next screen, shown in Figure 14-5, where the wizard prompts you to review the eld properties. Figure 14-5 Import Spreadsheet Wizard, screen 3

355

10. 10. Click the ZIP column header to display the corresponding eld properties. 0 k e nh header to cor co corresponding eld nd d 11. Click the Data Type down arrow and click Text, as shown in Fig 11. th the Data down arrow w rr r Text, shown Figure 14-6. h

Figure 14-6 e Change eld properties perties

Use the menu to change Use th menu to change the data type e u nge data ty e a type

Take Note

Access reviews the rst eight rows in each column to suggest the data type for the corresponding eld. If the column contains different types of values, the wizard suggests a data type that is compatible with all of the values in the columnusually the text data type. Although you can choose a different data type, values that are not compatible with the chosen data type will be ignored or converted incorrectly during the import process.

Copyright 2012 John Wiley & Sons

356

Lesson 14
12. Click Next > to display the next screen, as shown in Figure 14-7. Figure 14-7 Dene a primary key

13. Click Next > to let Access add the primary key. The nal screen appears, as shown Click Next e Access add he primary ce ce h i The nal screen app h c in Figure 14-8. e 14-8. 4-

Figure 14-8 8 Import Spreadsheet Wizard, , nal screen n

14. In the Import to Table box, key New Employees and then click Finish. When the Save Import Steps prompt appears, click Close. 15. In the Navigation pane, double-click the New Employees: Table to open the new table with imported data, as shown in Figure 14-9.

Copyright 2012 John Wiley & Sons

Import and Export Data

357

Figure 14-9 e New table with imported data d 16. Close the New Employees table. 16. 6. Employees table. e 17. LEAVE the database ope . 17. LEAVE 7 LE E database open ab ab e open. PAUSE. LEAVE Access open to use in the next exercise. exercise. PAUSE. LEA A E EA EAVE s open use in e s xer .

2.5.1 .5.1
How do you import source urce data into a new table? e?

Linking o n Exte nal Data Source Linking to an External Data Source tern te e a S rce 2.5.2 .5.2
How do you append records cords to an existing table? ?

By linking an Access datab e to data in another program, you can us the querying and reporty Access database data another e tabase t no h you o use ing tools that Access provides without havin to maintain a copy of the external data in your Access provides without having maintain i ing es e i ut t ing in n i database. You can also link to other external data sources, such as linkin tables in another Access also other external such linking data database. a h nal na n suc database (although you cannot link to queries, forms, or reports), H or HTML documents, or text database aa cannot link n les. In this exercise, you link to an Excel spreadsheet. you link les. In e u k When you link to an Excel works eet, Access creates a new table that i linked to the source cells, Excel worksheet, creates new is n you o E c w rksh k e called a linked table. The table shows the data in the source worksheet, but it doesnt actually linked abl linked table. The table ble ta in a worksh store the data in the database. Any changes you make to the source c in Excel appear in the cells ta in the database. y changes you a da hang nge linked table. However, you cannot edit the contents or structure of t corresponding table in However, you cannot edit the the e ou anno dit h not no Access. If you want to add, edit, or delete data, you must make the ch changes in the source le.

Take Note

If you dont want to link to the entire worksheet, dene a range that includes only the cells you want to link to. To create a named range, select the cells, right-click, and click Name a Range. In the New Name dialog box, key a name for the range and then click OK. After linking, you should open the linked table and review the elds and data to ensure that you see the correct data in all the elds. If you see error values or incorrect data, use Access Help to troubleshoot the source data and then try linking again.

STEP BY STEP

Link to an External Data Source


USE the database that is open from the previous exercise. 1. On the External Data tab, in the Import & Link group, click Excel to open the Get External DataExcel Spreadsheet dialog box. 2. Click Browse to open the File Open dialog box.
Copyright 2012 John Wiley & Sons

358

Lesson 14
3. Use the Look in box to locate the Benet_Providers spreadsheet le and then click Open. 4. Click Link to the data source by creating a linked table and click OK. The Link Spreadsheet Wizard appears, as shown in Figure 14-10.

The Benet_ Providers le for this lesson is available on the book companion website or in WileyPLUS. Figure 14-10 Link Spreadsheet Wizard, screen 1

5. Click Next > to display the next screen. Click l display e next screen. ne re 6. Click the First Row Contains Column Headings check box, shown i Figure 14-11, to Click l t w Contains Column Headings nt n ai s l H d box, shown in ox o s use use the rst row data as eld headin in the table. s w data as aa d headings in the e dings h Figure 14-11 1 Link Spreadsheet Wizard, , screen 2

Click Click this check box to use the first row as field headers box the first h r field i

7. Click Next > to display the next screen.


Copyright 2012 John Wiley & Sons

Import and Export Data


8. In the Linked Table Name box, key Benet_Providers, as shown in Figure 14-12. Figure 14-12 Link Spreadsheet Wizard, nal screen

359

9. Click Finish. A Li Spreadsheet Wizard message appears info 9. Click Finish. Li Spreadsheet Wizard message appears informing you that Access F Link p e sheet et s e ppe nished ni e nished linking. 10. 10. Click OK. 0 k OK. K

Troubleshooting If the table with the name you specied already exists, you are asked if you want to ooting f e with t name speci p already exists, r s
overwrite the existing le. Click Yes if you want to overwrite the le; click No to specify a overwrite e exis g le. Click Yes if you wa v is isting k y a overwrite rw different le name. different if name na na e. 11. In the Navigation pane, notice the linked Excel icon next to Benet_Providers. Double11. . Navigatio ation to notice i linked n n next Be click Benet_Providers to open the new linked table, shown in Figure 14-13. Notice c click o open p table, b that there is not an Add New Field column because the structure of a linked table because t that an Add w u structu cannot be changed. changed. can cannot g

Excel icon next to linked Benefit_Providers table object

Figure 14-13 New linked table


Copyright 2012 John Wiley & Sons

360

Lesson 14
12. Click the Close button on Benet_Providers to close the table. 13. OPEN Excel and open the Benet_Providers spreadsheet. 14. Key the new row of data shown in Figure 14-14.

Key the new data into row 6 of the Excel worksheet

Figure 14-14 New Excel data a 15. Save and close the spreadsheet. 16. CLOSE Excel. 17. In the Navigation pane of Access, double-click Benet_Providers to open the linked Navigation pan of Access, doub e clic tio pane double-click oub Notice that been a in table. Notice th the new row of data has been added, as shown i Figure 14-15. ti h e added, Figure 14-15 5 New Excel data added to o linked table e

New data appears in a linked Access table w ta appears in linked Access table ta ea a nk k c bl

2.5.3
How do you import data as a linked table?

18. Close the Benet_Providers table. Close Benet_Pro t_Providers table. l 19. LEAVE the database open. LEAVE E V PAUSE. LEAVE Access open to use in the next exercise. E. LEAVE open t use in pen pe pe

SAVING AND RUNNING IMPORT SPECIFICATIONS AND RUNNING ND SPEC SPECIFICATIONS


The Bottom Line

Saving the details of an import operation as a specication allows you to repeat the operation at import operat o mpor operatio or operation r any time. A specication contains all the information Access needs to repeat an import or speci ion spec catio specication export operation without user i input. Wh you run an i When import wizard, you can save the settings i ih i d you used as a specication so that you can repeat the operation at any time without having to provide any additional input. A specication is exible. For example, you can change the name of the source le or the destination le before you run the specication again. This way, you can use a single specication with several different source or destination les.

Take Note

If you regularly repeat this saved operation, you can create an Outlook task that reminds you when it is time to perform this operation by clicking the Create Outlook Task check box. To use a text le as a source le for importing, the contents of the le must be organized in such a way that the Import Wizard can divide the contents into a set of records (rows) and each record into a collection of elds (columns). Two types of text les that are organized for importing are delimited les and xed-width les. In a delimited le, each record appears on a separate line and the elds are separated by a single character, called the delimiter. The delimiter can be any character that does not appear
Copyright 2012 John Wiley & Sons

Import and Export Data

361

in the eld values, such as a tab, semicolon, comma, space, and so on. The following is an example of a comma-delimited le: Company Name,Employee Name,Position Fourth Coffee,Dana Burnell,Sales Manager Woodgrove Bank,Michael Emmanuel,Vice President Wingtip Toys,Billie Murray,Owner In a xed-width le, each record appears on a separate line and the width of each eld remains consistent across records. For example, the rst eld of every record is always 9 characters long, the second eld of every record is always 14 characters long, and so on. If the actual character length of a elds value varies from record to record, the values that fall short of the required width must be padded with trailing space characters. The following is an example of xed-width le where the rst eld is said to be 16 characters, second eld is said to be 20 characters and third eld is said to be 14 characters: Company Name Employee name Position Sales Manager Fourth Coffee Dana Burnell Michael Emmanuel Vice Woodgrove Bank Michael Emmanuel Vice President k Michae Emmanuel Vic h Toys Billie Wingtip Toys Billie Murray oy Owner

Saving Specications Saving Specications v vi ci ci atio i io ions


You can You can save an import or export operation involving any of the le formats supported in o export o ng ng Access, but you cannot save the details of a linking operation or an operation where you operation Ac Access, e the h e export only a portion of a datasheet. In this exercise you import a t le and then save the exercise you import text export only portion f datasheet. In por nl l io o a sheet erc r u import specications. import specications. rt e t
STEP BY STEP

Save Import Specications Save Import Specications mp r p at n atio at ns


USE USE the database that is open from the previous exercise. database t s is open from t previous exercise. op r the r io i .

The Applicants le for this lesson is available able on the book companion ion website or in WileyPLUS. LUS.

1. 1. On the External Data tab, in the Import & Link group, click Text File to open the Get External Data tab, n he Import te a ata b a e p group, click p DataText e dialog box. External DataTe File dialog box. at t Text Te e a o 2. Click Browse to open the File Open dialog box. . to e File l n dialog 3. Use the Look in box to locate the Applicants text le and then click Open. 3. Use U locate o t s e 4. Click Import the source data into a new table in the current database and click OK. The Cli Click e sourc data rc rce a n the h da Import Wizard appears, Impo Text Wizard appears, as shown in Figure 14-16. mpo port a pp s Figure 14-16. u

Figure 14-16 Import Text Wizard, screen 1 reen

Copyright 2012 John Wiley & Sons

362

Lesson 14
5. Click Next > to display the next screen, shown in Figure 14-17. Figure 14-17 Import Text Wizard, screen 2

6. Comma should be selected as the delimiter. Click the First Row Co Comm ho Comma should o m selected as e delimiter. el e ed e ck the First h i t Contains Field Names check box o rst ow data as headings the check box to use the rst row data as eld headings in the table. e o st st w a at d g e 7. Click Next > to display the next screen, shown in Figure 14-18, where you can specify Click l xt to t e next screen, n n n 14-18, whe 4 eld e information. eld information. m o Figure 14-18 8 Import Text Wizard, , screen 3

Copyright 2012 John Wiley & Sons

Import and Export Data


8. Click Next > to accept the default settings and display the next screen, shown in Figure 14-19, where you can dene a primary key. Figure 14-19 Import Text Wizard, screen 4

363

9. Click Next > to let Access add the primary key and to display t nal screen, shown 9. k Next ex Access dd the c ss key y to display the Figure in Figure 14-20. g e Figure 14-20 Import Text Wizard, nal screen

Copyright 2012 John Wiley & Sons

364

Lesson 14
10. Click Finish to accept the default table name. A Save Import Steps screen appears. 11. Click the Save import steps check box to display the specication details, shown in Figure 14-21. Figure 14-21 Save Import Steps screen

12. In the Description box, key Import text le with job applicant contact information. Description s pt y Import or with jo applicant cont t o l a 13. Click Save Import. Click l Import. m 14. In the Navigation pane, double-click the Applicants: Table to open t new table with Navigation a n , doub -c k the Applicants: Table to double-click c pp ic l the imported imported data, as shown in Figure 14-22. m a, , s ow shown i Figure 14-22. ur 4-2 u Figure 14-22 2 New table with imported data a

15. Close the Applicants table. 16. LEAVE the database open. PAUSE. LEAVE Access open to use in the next exercise.

Copyright 2012 John Wiley & Sons

Import and Export Data

365

Running Import Specications


To run a saved specication, on the External Data tab, in the Imports group, click Saved Imports. In the Manage Data Tasks dialog box, on the Saved Imports tab, click the specication that you want to run. In this exercise, you run import specications. If you want to change the source le, click the path of the le to edit it. The new le you specify must satisfy all the requirements essential for successfully completing the operation. Before you click Run, make sure that the source and destination les exist, that the source data is ready for importing, and that the operation will not accidentally overwrite any data in your destination le. Do everything that you would do to ensure the success of a wizard-driven operation before running any saved specication and then click Run. If you no longer need to perform a specic operation, you can delete the specication by selecting it and clicking Delete.

STEP BY STEP

Run Import Specications Specications cations s


USE the database that is open from the previous exercise. database t ab previous ev ou v 1. On the External Data tab, in the Import & Link group, click Saved Imports to open the n the External Data a the nk group, k Sav Tasks 14-23. Manage Data Tasks dialog box, shown in Figure 14-23. Ma Ma a Ta g box, e 14

Click pa h name o edit Click path nam to edit ic path am c me d

D Description of specification o

Figure 14-23 Manage Data Tasks dialog box

Copyright 2012 John Wiley & Sons

366

Lesson 14
2. Click the le path and edit it by changing the source le name to March Applicants.txt, as shown in Figure 14-24.

Figure 14-24 Changing source le name

Edit file name

3. Click Run. A me sage appears aski if you want to overwrite the e Click l message ap essa appears asking if you want overwrite asking o r existing table, as shown Figure 14-25. shown in Figure 14-25. h r 42 .

Figure 14-25 5 Overwrite message e

4. Click Yes. A message appears conrming that all objects were successfully imported, as shown in Figure 14-26.

Figure 14-26 Successful import message

o yi

o n Wiley & Sons

Import and Export Data


5. Click OK. 6. Click Close to close the Manage Data Tasks dialog box. 7. In the Navigation pane, double-click the Applicants: Table to open the table. The existing data has been replaced with new imported data, as shown in Figure 14-27.

367

Figure 14-27 Table with new imported data d 8. Close the Applicants table. 8. Applicants table. l a s b 9. LEAVE the database open. 9. database open. a b e PAUSE. LEAVE Access open to use in the next exercise. exercise. PA PAUSE. Access cce cc c use he he e

EXPORTING DATA EXPORTING DATA POR O A A


The Bottom Line ne

To use Access data in another program, you can use the various comm Access dat ess es data you can use u n commands in the Export group to export the selected object in the format you want. selected obj t in the format you le ted bject l ct d bj ma a

Exporting from a Table


When you export data from a table to Excel, Access creates a copy of the data and then stores the copy in an Excel worksheet. In this exercise, you export data from an Access table to an Excel worksheet. Besides exporting to Excel, you can also export data to other destinations, such as a SharePoint list, a Rich Text Format le, another Access database, or a text le. The process for exporting data is similar, regardless of the destination.

o yi

o n Wiley & Sons

368

Lesson 14

Table 14-2 summarizes the options for creating or overwriting a workbook.


Table 14-2 Destination Workbook Options

Destination Workbook Does not exist Source Object Table, query, or form Table or query Exported With or without formatting Without formatting

Data Result Workbook is created during the export operation. The workbook is not overwritten. A new worksheet is added to the workbook and is given the name of the object from which the data is being exported. If a worksheet having that name already exists in the workbook, Access prompts you to either replace y the contents of the corresponding th worksheet or specify another name for spe the new sheet. The workbook is overwritten by the exported data. All existing worksheets exported xp are removed, and a new worksheet are removed, r r having the same name as the exported having av g n object is created. The data in the Excel o e t object T worksheet inherits the format settings of wor ksheet inherit rk h the source object. sou source object ur

Already exists

Already exists exists xs s

Table, query,, quer quer y ry or form form om

With formatting With i

If the source object is a table or a quer , de e whether you want to ex the h object e table or query, de b bl uery ecide ue ue decide whether want export the data with or a without its formatting. If you choose without formatting, all elds and records in the underlying without formatting. If you choose without formatting, h u i u o th h form fo m elds ds reco object are exported and the Format property settings are ignored during the operation. If you object are c an the Format property settings n h m rt rt e ignored o ed choose with formatting, only the elds and records displayed in the current view are exported records choose with formatting, s ng g elds l re d n curr and the Format property settings are respected. the Format h are respected. You can exp rt a table, query, or form to Excel. You can only export on database object in a export one expo query, form y, , r n only single export operation. However you can merge the data in multiple worksheets in Excel after export operation. However, y or or o wever you ever er, data in aa wo completing the individual export operations. The data is always added in a new worksheet. You data is h n he individual export p ata cannot append the data to an existing worksheet. the data to n existing worksheet. h ta x n orksheet. kh

STEP BY STEP

Exporting from a Table


USE the database that is open from the previous exercise. 1. In the Navigation pane, select the Part-Time Employees: Table. 2. On the External Data tab, in the Export group, click Excel. The ExportExcel Spreadsheet dialog box appears, as shown in Figure 14-28.

o yi

o n Wiley & Sons

Import and Export Data


Figure 14-28 ExportExcel Spreadsheet dialog box

369

3. If you want to specify a different destination, click Browse to open the File Save dialog . different e Browse r o box, s Save n box choose choose box, use bo use the Save in box to cho se a folder, and then click Save. o av av x d then Sav 4. Click the Export data with formatting and layout check box and then click the Open the 4. Click the c h data with formatting a o a layout check a o h an destination export destination le after the export operation is complete check box. ti ti r o or is complete e b 5. Click OK. Excel opens and the new worksheet with exported data is displayed, as 5. OK. E Excel and the h worksheet sh shee exported d p shown in Figure 14-29. i Figure i 9 9.

Figure 14-29 Excel worksheet with exported data

o yi

o n Wiley & Sons

370

Lesson 14
6. Close the worksheet and CLOSE Excel. 7. Switch to Access. 8. On the Save Export Steps screen, click Close. 9. LEAVE the database open. PAUSE. LEAVE Access open to use in the next exercise.

Exporting from a Query


You can export data from an Access query to a variety of formats, just as you can export data from an Access table. In this exercise, you export a query to Word. You can export a table, query, form, or report to Word. When you export an object to Word, Access creates a copy of the objects data in a Microsoft Word Rich Text Format le (*.rtf ) and the visible elds and records appear as a table, with the eld names in the rst row.
Take Note

Pictures or attachments that are part of the source data are not exported to Word. Expressions are not exported either, but the results are. he results are. e esults export fr xp r rom p nt he n the When you export from Access to a Word document, th Export Wizard a document, th always exports formatnd the d s always exported lways ex rted expo t d Wor Word cann ted data and the data is always exported into a new Word le. You cannot append data to an Word document. ment e existing Word document.

STEP BY STEP

Export from Query Export from a Query po p rt rom er r


USE the database that is open from the previous exerc E the database h ta s open from the pe h exercise. x rcise. c 1. In the Navigation pane, select the Part-Time Employees Query. Navigation vi ti select the le h e Emp mployees Query. u 2. On the Exter l Data tab, in the Exp n External ernal er e ,i Export group, click the More button. On the menu xport group, click u More butto r that appears, click Word. The ExportRTF File that appears, click Word. The ExportRTF File dialog box appears, as shown in h s c d h xp t e box appears, o Figure Figure 14-30. g

Figure 14-30 0 ExportRTF File dialog box x

3. If you want to specify a different destination, click Browse to open the File Save dialog box, use the Save in box to choose a folder, and then click Save.

o yi

o n Wiley & Sons

Import and Export Data

371

4. Click the Open the destination le after the export operation is complete check box. 5. Click OK. Word opens and the new document with exported data is displayed, as shown in Figure 14-31.

Figure 14-31 Word document with t exported data d 6. Close the document and CLOSE Word. 6. e e n CLOSE L 7. Switch to Access. 7. to Access. 8. On the Save Export Steps screen, click Close. 8. Save Export Steps screen, a E rt e t c n Cl Close. 9. LEAVE the database open. 9. e database open. taba b e PAUSE. LEAVE Access open to use in the next exercise. next PAUSE. A Access s use n .

SAVING SAVING AND RUNNING EXPORT SPECIFICATIONS A RUN NG UNNING UN G SPECIFICATION CF


The Bottom Line ne

When you perform an export operation, you can save the details for fu n you o an export operation, xp r p save the ve v future use so you can repeat the operation at a later time without having to walk through the step in the wizard each time. operation steps r to r time without ime wa k walk You can even schedule the export operation to run automatically at s operation to run specied intervals by creatn schedu e ched edul ed i n ing an Outlook task. task. s In the Save as box, type a name for the export specication. Optionall type a description in the Optionally, Description box. If you want to perform the operation at xed intervals, such as weekly or monthly, select the Create Outlook Task check box. Doing this creates an Outlook task that lets you run the specication by clicking a button. You can change the name of the specication, its description, and the path and le name of the destination le by clicking and making changes in the text box and then pressing Enter. Repeat an operation by clicking the specication and then clicking Run. If you are exporting data with formatting and layout, you are asked to choose the encoding to be used for saving the le. When the operation is complete, you will see a message that communicates the status of the operation. Although you can export Access data in various formats, sometimes you might need to export data to a program that uses a le format that Access does not support. In that case, if the destination program can use text (*.txt) les, you can export your data in that format and open the resulting le with the second program. When you export the contents of a table or query to a text le with formatting and layout, hyphens (-) and pipe characters (|) are used to organize the content in a grid in the text le. The records appear as rows, elds appear as columns, and eld names appear in the rst row.
o yi o n Wiley & Sons

372

Lesson 14

When exporting without formatting or layout, the Export Wizard gives you the option of creating a delimited le or a xed-width le, as shown in Figure 14-32.
Figure 14-32 Export Text Wizard le options

The choice you make usually dep nds on the system th works with the exported les. If users c i choice u usuall de d n he su lly depe depends he that works r s need to look at the data, a xed-width le can be much easier to read than a delimited le. the xed-width e much easier to d to ok t t d- th h c a

Saving Export Specica n Saving Export Specications av xp r p cations


After you After you have performed an expo opera e performed export operation, you are given the opportun to save it for future e o xport ration, u are ra r e opportunity p use. Saving the details helps you repeat the same export operation in the future without having you repeat he . Saving a details et l eat e e export operation p t n f to step through the wiza d each time. In this exercise, you export data from Access to a text le, export step t e wizard each time. n thi exerci zard c za ac i . his e cise, i ot and then save the export spe cation. then he export speci at n. x t pecica pe ation at
STEP BY STEP

Save Export Specications e Export i i s


USE the database that is open from the previous exercise. database a s open from en e r exercise. cs 1. In the Navigation pane, select the New Employees: Table. Navigation pane, sele t vg ne select e le Employees: oyee y 2. On the External Data tab, in the Export group, click Text File. The Ex External Da rnal Data t group, grou oup ou ExportText File Figure dialog box appears, as shown in Figure 14-33. appears s shown Figure 14-33. rs, rs ure

Figure 14-33 3 ExportText File dialog box

o yi

o n Wiley & Sons

Import and Export Data

373

3. If you want to specify a different destination, click Browse to open the File Save dialog box, use the Save in box to choose a folder, and then click Save. 4. Click the Export data with formatting and layout check box and then click the Open the destination le after the export operation is complete check box. 5. Click OK. The Encode New Employees As dialog box is displayed, as shown in Figure 14-34. Figure 14-34 Encode New Employees As dialog box

6. Windows (default) should be selected. Click OK. Notepad open and the new le with opens exported data is displayed, as shown in Figure 14-35.

Figure 14-35 Notepad with exported data d 7. CLOSE Notepad. 7. Notepad. t 8. Switch to Access. 8. o Access. c 9. On the Save Export Steps screen, click the Save export steps c 9. Save Export Steps screen, click the v Exp r po p c en li ic export p r check box to display the shown n Figure specication details, as shown in Figure 14-36. n details, a s ur

Figure 14-36 Save Export Steps screen

o yi

o n Wiley & Sons

374

Lesson 14
10. In the Description box, key Export new employee information to a text le. 11. Click Save Export. 12. LEAVE the database open. PAUSE. LEAVE Access open to use in the next exercise.

Running Export Specications


When you run the Export Wizard, you can save the operation as a specication for future use. In this exercise, you run the export specications you just saved.

STEP BY STEP

Run Export Specications


USE the database that is open from the previous exercise. 1. In the Navigation pane, double-click the New Employees: Table to open it. o 2. Add another record with the following info record with the followin information: co d ith h following nformation: o t o i First Name: Rachel Name: Ra h e Rachel Last Name: Valdez Name: a am Address: Address: 39 Vista Drive r s a Drive i City: Roanoke City: Roanoke t ty Stat Stat State: VA tate: t ZIP: 94510 ZIP: 94510 4 Phone Number: 607.555.1218 h m 55. 218 Phone Number: 607.555.1218 3. Click the Close New Employees button to close the table. Click l C s Close Employees po s close the table. o l 4. On the External Data tab, in the Export group, click Saved Exports to open the Manage n External e a n Export group, click Saved Exports x p e Data dialog shown Figure 14-37. Data Tasks dialog box, show in Figure 14-37. a i g hown ho g gu 37 7

Figure 14-37 7 Manage Data Tasks dialog box x

Click Click path name to edit c name e

Description of specification

o yi

o n Wiley & Sons

Import and Export Data

375

5. Click the le path and edit it by changing the destination le name to New Employees 2.txt, as shown in Figure 14-38.

Figure 14-38 Edit destination le

Edit file name

6. Click Run. Notepad opens and the new le with exported data is displayed, as shown 6. Click opens and n exported xp in Figure 14-39.

Figure 14-39 Notepad with exported data d 7. Switch to Access. A message conrms that the export operation was successful, as Switch Access. m s witch s message the h operatio shown in Figure 14-40. n n Figure

Figure 14-40 Successful export operation message

8. Click OK and then click Close to close the Manage Data Tasks dialog box. 9. CLOSE Notepad. 10. CLOSE the database. PAUSE. LEAVE Access open to use in the projects.

o yi

o n Wiley & Sons

376

Lesson 14

SKILL SUMMARY
In This Lesson You Learned How To: Import Data Exam Objective Import source data into a new table. Append records to an existing table. Import data as a linked table. Objective Number 2.5.1 2.5.2 2.5.3

Save and Run Import Specications Export Data Save and Run Export Specications Specications

Knowledge Assessment ssment


Fill in the Blank in B n Blank
Complete Complete the fo wing sentences by writing the correct word or words in the b m l follow following s wri writing r ri t word words d blanks provided.

1. When you import data, Access creates a(n) When import o Access creates cc cc ea e existing le. existing table without alt ring the source le. x le without altering the source l e it t lter lt in h o t

of the data in a new or

2. When you link to an Excel worksheet, Access creates a new table, called When h k an Excel worksheet, Access c k e ce s new w a(n) a a(n) , that is linked to the source cells. that s linked to the source n d h contains all the information Access needs to repeat an import or all in o information Access e s 3. A(n) A(n) export without user input. export operation without user input. x o e n le, each record appears on a separate line and the elds are each c separate lin 4. In a(n) a(n a(n) separated by a single character. single character. separat d arate a l a c . is any character that separates elds and does not appear in the s any character c separates arat rate do 5. A(n) values, such tab, comma, or eld values, su as a tab, semicolon, comma, or space. es, es b ma, a rec lin le, each record appears on a separate line and the width of le, each reco d appears record 6. In a(n) consistent each eld remains consistent across records. i t t 7. You can schedule an import or export operation to run automatica at specied 7 automatically task. intervals by creating a(n) 8. When you export the content of a table or query to a text le with and , hyphens (-) and pipe characters (|) are used to organize the content in a grid. 9. When exporting to Excel, the data is always added in a new 10. To repeat an import or export operation, click the specication and then . click .

Multiple Choice
Select the best response for the following statements or questions.

1. Which tab contains options for importing or exporting data? a. Manage Data b. Database Tools c. External Data d. Create
o yi o n Wiley & Sons

Import and Export Data


2. Before beginning an import operation, the source le should be a. Open b. Closed c. Copied d. Backed up

377

3. If you want to add, edit, or delete data in a linked table, you must make the changes in the a. First row of data b. Access object c. Field headers d. Source le 4. You can save an import or export operation involving any of the le formats supported in Access, but you cannot save the details of a a. Linking operation b. Text le import operation operation pe peration n c. Query export ope ti y e port operation export peration i d. Fixed-width le Fixed-width ixedxed5. The following is an example of what kind of text Th The following is g example of pl pl text? ext? 1 1, Fourth Coffee, Dana, Burnell, Sales Manager Coff ffee, Burnell, un a. HTML b. Linked b. Linked L ke c. Fixed-width F ed Fixed-width d. Comma-delimited C Comma-delimited m d 6. How many database objects can you expo t in a single export operation? 6. many y objects b t export port po single n e a. One b. Two c. Three d. Unlimited d 7. When you export an object to Word, Access creates what type of le? 7. export p object j Access creates what e a. a. MS-DOS Text b. R b. Rich Text Format Rich Format m c. HTML HT HTM d. Linked Linked k d 8. If you choose to store imported data in a new table, Access to store imported data tore mported da e orte or e a. Links the new table to an existing table b. Overwrites the data in the existing table c. Creates a table and adds the imported data to this table d. Gives you an error message 9. What is an advantage of linking an Access database to data in another program? a. Maintaining a copy of the external data in Access b. Being able to use Access querying and reporting tools c. Being able to edit the linked table in Access d. Easily being able to change the structure of the Access table 10. Which dialog box allows you to manage saved import and export specications? a. External Data b. Saved Specications c. Import/Export Tasks d. Manage Data Tasks

o yi

o n Wiley & Sons

378

Lesson 14

Competency Assessment
Project 14-1: Import Data from Excel
You are the purchasing manager for Coho Wine Club and an associate has provided some information about champagne and sparkling wines that are being considered for the monthly wine club. The data is in an Excel worksheet and will need to be imported into the database.

GET READY. LAUNCH Access if it is not already running. The Coho Wine Club le for this lesson is available on the book companion website or in WileyPLUS. 1. OPEN the Coho Wine Club database from the data les for this lesson. 2. SAVE the database as Coho Wine Club XXX (where XXX is your initials). 3. On the External Data tab, in the Import & Link group, click Excel to display the Get External DataExcel Spreadsheet dialog box. 4. Click Browse to open the File Open dialog box. g spreadsh 5. Use the Look In box to locate the Champagne_Sparkling spreadsheet le and then click Open. 6. Click Import the source data into a new table in the current database and click OK. t the source he tabl table i ble bl databa Import Spreadsheet appears. The Import Spreadsheet Wizard appears. port o p 7. Click Next > to display the next screen. N Next display the next screen. sp sp a h 8. Click the First Row Contains Column Headings check box. Click the c th Column l ck box. k 9. Click Next > to display the next screen where the wizard prompts y Click l next e wizard ad you to review the eld propert ld properties. d ropert roperties. t 10. Click the Bottled column heading to display the corresponding eld properties. Click the Bottled colum h ic h Bo umn um heading to display n corresponding el r p n 11. Click the Data Type down arrow and click Text. Click e Data i ta t wn arrow and n rro r d 12. Click Next > to display the next screen. Click l t o en next screen. 13. Click Next > to let Access add the primary key. The nal screen appears. Click l l let add primary key. The ey e screen app r 14. In the Import to Table box, key Champagne_Sparkling and then click Finish. When the t t Table box, key Ch mpagne_Sp a o ke Champ e p e_Sparkling and then clic n Save Steps prompt appears, clic Clos Save Import Steps prompt appears, click Close. a t s r m e s click os se. 15. In the Navigation pane, double-click the Champagne_Sparkling: Table to open the new In the Navigation pane double-click the Champagne_Sparkling: Tab o ane, e b k h h par ta table with imported data. te te table imported data. 16. Close the Champagne_Sparkling table. Clos lose s Champagne_Sparkling k g 17. LEAVE the database open for the next project. LEAVE AVE AV AV op n o h open for the LEAVE Access open for the next project. Access c e t ne t ro the next pro roject.

The Champagne_ Sparkling le for this lesson is available on the book companion website or in WileyPLUS.

Project 14-2: Export Data to Word Export Data o Word xport at port or
Your supervisor at Coho Vineyard wants a list of the distributor information in a Word le. Use the Distributor table in the Access database to export the data to a Rich Text Forma le. Format

USE the database that is open from the previous project. 1. In the Navigation pane, select the Distributors: Table. 2. On the External Data tab, in the Export group, click Word to display the ExportRTF File dialog box. 3. If you want to specify a different destination, click Browse to open the File Save dialog box, use the Save in box to choose a folder, and then click Save. 4. Click the Open the destination le after the export operation is complete check box. 5. Click OK. Word opens and the new le with exported data is displayed. 6. Close the le and CLOSE Word. 7. Switch to Access. 8. On the Save Export Steps screen, click Close. 9. CLOSE the database. LEAVE Access open for the next project.

o yi

o n Wiley & Sons

Import and Export Data

379

Prociency Assessment
Project 14-3: Save Export Specications
As a travel agent at Margies Travel, a client asks you to email information about the dates for available travel packages. Because you dont know what program the client will use to open it, you export the data to a text le. Because you do this frequently, you decide to save the export operation as a specication that can be used later.

GET READY. LAUNCH Access if it is not already running. The Trip Events le for this lesson is available on the book companion website or in WileyPLUS. 1. OPEN the Trip Events database from the data les for this lesson. 2. SAVE the database as Trip Events XXX (where XXX is your initials). 3. In the Navigation pane, select the 2011 Events: Table. 4. On the External Data tab, in the External group, click Text File to display the ExportText File dialog box. 5. Specify the location where you want to store the le. location where you want tion here u on le. 6. Click the Export data with formatting and layout check box and then click the Open the e Export data E po t formatting and ttin tt n n an destination destination le after the export operation is complete check box. inati n t n s complete b 7. Click OK. The Encode 2011 Events As dialog box is displayed. C ick Click En Encode Events box ox 8. Windows (default) should be selected. Click OK. Notepad open and the new le with . Windows (default) f ld be d No No otepad opens exported displayed. e exported data is displayed. y 9. CLOSE Notepad. . CLOSE Notepad. CLOS CL S ad d 10. Switch Access. 10. Switch to Access. 0 w h s 11. On the Save Export Steps screen, click the Save export steps check box. 11. 1 the Save rt Steps screen, t e e Sav Sa Save export p r c 12. 12. In the Description box, key Export event information to a text le. 2 e Description box, s x Export information to n 13. 13. Click Save Export. 3 Save Export. a 14. LEAVE the database open. 14. 4 the database open. h a s p LEAVE Access open for the next project. LEAVE E s open fo the next project e for xt x r ct ct.

Project Project 14-4: Run Export Specications Run un Specications on


One of the trip packages is no longer available. Delete the information from the table and run the ne o e es s s longer o e info information export specication to create a new text le with the updated information. or ort ort o create t w update information d t dated

USE the database that is open from the previous project. the da h database that s open ha a pen e previous project. u 1. Open the 2011 Events: Table. he 2011 Events: e2 2. Delete the World Series record from the table. World Series record fr l Se i s ecor fro Seri cord from 3. Close the 2011 Events table. 4. On the External Data tab, in the Export group, click Saved Exports. 5. Click the le path and change the destination le name to 2011 Events updated.txt. 6. Click Run. Notepad opens and the new le with exported data is displayed. 7. Switch to Access. A message conrms that the export operation was successful. 8. Click OK and then click Close to close the Manage Data Tasks dialog box. 9. CLOSE the database. LEAVE Access open for the next project.

o yi

o n Wiley & Sons

380

Lesson 14

Mastery Assessment
Project 14-5: Export Data to a New Database
You are the manager at Southridge Video. You have created a new database to store information about new video games. You want to export the Games table to the new database. You have exported an Access table to other destinations, but not to another Access database. Use Access Help if you need more information.

GET READY. LAUNCH Access if it is not already running. The Sale Games le for this lesson is available on the book companion website or in WileyPLUS. 1. Create a new le called New Games XXX (where XXX is your initials). 2. CLOSE the New Games database. 3. OPEN Sale Games from the data les for this lesson. 4. Save the database as Sale Games XXX (where XXX is your initials). 5. Use the export skills you have learned in this lesson to export the data and denition d of the Games table to the New Games XXX database. o the New Game h Ne Game Game es X 6. Do not save the export steps. the ex h export 7. OPEN the New Games XXX database to be sure the Games table w successfully he New Games XXX database e e ataba re h re the was exported. exported. rt rte 8. CLOSE both the databases. CLOSE OSE OS d databases. LEAVE Access open for the next project. E Access t project. o

Project 14-6: Appending Data Project 14-6: Appending Data to a Table oj o c 4 n at Tab Table
You are the human resources manager for Contoso, Inc. You have received information about new e the human um n m manager or an o Yo ou rec iv infor ecei e iv ived employees that needs to be imported into the employee database. You already have a table with employees p y t needs n imported into rte nt t t ee da ee database. You information about sales reps, so you want to append the information instead of creating a new table. information om ut le ut sales yo tt th the information instead o o Because you have never appended data before, use Access Help if you need add never appended data b or before, Access you need additional information. Because ca s e d de r A e u

The Contoso Employees le for this lesson is available on the book companion website or in WileyPLUS. The New_Contoso le for this lesson is available on the book companion website or in WileyPLUS. Figure 14-41 1 Appended data

GET READY. LAUNCH Access if it is not already running. T READY. LAUNC Access t NC NCH c s ot l ead ot already running. dy 1. OPEN the Contoso Employees database from the data les for this lesson. OPEN PE Contoso Employees database from os E s ee e as as r les e 2. SAVE the database as Contoso Employees XXX (where XXX is your initials). SA SAVE database s Contoso Employee o ees ee ee X (where XXX you r 3. Choose to import from Excel using the New_Contoso spreadsheet le. Choose hoo l using s o spreadsheet 4. Choose the options necessary to append the spreadsheet data to t Sales Rep table. Choose o e necessary to s r spreadsheet dsh ds the 5. Do not sav the import steps. t save ave import steps. o teps ps. 6. Open the Sales Reps: Table. The data from the Ex Sale Sales ale the Excel spreadsheet sh should be appended to the table, as shown in Figure 14-41 shown in Figure 14-41. ho n Figure 4-41 e 41. 1

o yi

o n Wiley & Sons

Import and Export Data


7. Close the Sales Reps table. 8. CLOSE the database. CLOSE Access.

381

INTERNET READY
To display the contents on the Access Help tab, click the File tab and then click the Help tab. The contents of the Access Help tab, shown in Figure 14-42, is where you can contact Microsoft, nd online resources, and the maintain

health and reliability of your Ofce applications. To keep your computer up-to-date, click the Check for Updates button to go to the Microsoft update site. Here you can check to see if you need updates for your programs, hardware, or devices.

Figure 14-42 Access Help tab elp

o yi

o n Wiley & Sons

Das könnte Ihnen auch gefallen