Microsoft KB Archive/162539

= ACC: #Num Appears in Linked Microsoft Excel Spreadsheet =

Article ID: 162539

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q162539



Moderate: Requires basic macro, coding, and interoperability skills.



SYMPTOMS
When you link to a Microsoft Excel 7.0 or 97 spreadsheet from a Microsoft Access 7.0 or 97 database, and the fields in the spreadsheet contain both numbers and text, the fields that contain text appear as #Num! in the linked table in Microsoft Access.



CAUSE
Microsoft Access assigns the data type for each field based on data contained within the first eight rows it links. For example, if a field that contains mostly text values has a number in the first eight rows, Microsoft Access assigns the Number data type, and then cannot link the rest of the records. Any format that you apply to the fields in Microsoft Excel will be ignored by Microsoft Access when the spreadsheet is linked. NOTE: When you import rather than link an Excel spreadsheet, the Text data type has a priority within the import algorithm. For example, if the predominant data type based on a sampling of data is numeric, but there is at least one text value within that sample, Microsoft Access will import the entire field as text.



RESOLUTION
Before you link to the spreadsheet in Microsoft Access, make sure that the spreadsheet has the same type of data in each field (column) and the same fields in every row.

-or-

Use the following procedure to format the cells in the spreadsheet so that they will appear correctly in Microsoft Access.

Formatting the Cells in the Microsoft Excel Spreadsheet
To format the cells in the spreadsheet so that the linked table data appears correctly in Microsoft Access, follow these steps:  Open the spreadsheet in Microsoft Excel 7.0 or 97. Format the cells in the spreadsheet that contain mixed data as Text. You should do this from the Format menu in Microsoft Excel.  Create a macro in Microsoft Excel that contains the following procedure: Sub Addspace

Dim cell As Object

For Each cell In Selection cell.Value = " " & cell.Value cell.Value = Right(cell.Value, Len(cell.Value) - 1) Next End Sub  Highlight the cells in the spreadsheet that contain the mixed data. Run the macro, and then save the spreadsheet. Open your database in Microsoft Access 7.0 or 97.</li> Link to the spreadsheet that you created in Microsoft Excel. Note that your data is now in the correct format.</li></ol>

<div class="moreinformation_section">

Steps to Reproduce Behavior
<ol> Start Microsoft Excel and create a new spreadsheet.</li> Type the following in cells A1 through A5:

A1: 12345

A2: 12345

A3: 12345

A4: 12345

A5: 12345A

</li> Save the spreadsheet as Book1, and then close Microsoft Excel.</li> Open the sample database Northwind.mdb in Microsoft Access.</li> On the File menu, point to Get External Data, and then click Link Tables.</li> In the Link box, click Microsoft Excel in the Files Of Type list, and then select the Book1 spreadsheet that you created. Click Link.</li> In the Link Spreadsheet Wizard, click Next twice, accept Sheet1 for the Linked Table Name, and then click Finish.</li> Click OK in the Link Spreadsheet Wizard message box.</li> Open the linked table (Sheet1). Note the #Num! in the last record.</li></ol>

<div class="references_section">