ACC: Imported MS Excel Carriage Returns Become Vertical Bars (115576)
The information in this article applies to:
- Microsoft Access 2.0
- Microsoft Access for Windows 95 7.0
- Microsoft Access 97
- Microsoft Excel 97 for Windows
- Microsoft Excel for Windows 95
- Microsoft Excel for Windows 2.0
- Microsoft Excel for Windows 2.01
- Microsoft Excel for Windows 2.1
- Microsoft Excel for Windows 2.10c
- Microsoft Excel for Windows 2.10d
- Microsoft Excel for Windows 3.0
- Microsoft Excel for Windows 3.0a
- Microsoft Excel for Windows 4.0
- Microsoft Excel for Windows 4.0a
- Microsoft Excel for Windows 4.0c
- Microsoft Excel for Windows 5.0
This article was previously published under Q115576
Moderate: Requires basic macro, coding, and interoperability skills.
SYMPTOMS
When you import a Microsoft Excel spreadsheet into Microsoft Access, the
carriage return (CR) character appears as a vertical bar or a small box,
depending on your version of Microsoft Excel and Microsoft Access. For
simplicity, this article refers to vertical bars to indicate either
vertical bars or small boxes.
For example, if you import a Microsoft Excel spreadsheet mailing list
with complete addresses stored in single cells formatted with carriage
returns, the addresses appear in Microsoft Access as single lines with
vertical bars between the address items.
This article assumes that you are familiar with Visual Basic for
Applications and with creating Microsoft Access applications using the
programming tools provided with Microsoft Access. For more information
about Visual Basic for Applications, please refer to your version of the
"Building Applications with Microsoft Access" manual.
NOTE: Visual Basic for Applications is called Access Basic in Microsoft
Access version 2.0. For more information about Access Basic, please refer
to the "Building Applications" manual.
CAUSE
The CR character used in Microsoft Excel (ALT+ENTER) differs from that
used in Microsoft Access (CTRL+ENTER). As a result, the CR characters
in Microsoft Excel spreadsheets are not parsed into carriage returns in
Microsoft Access, but into small vertical bars.
RESOLUTION
You can use the following sample user-defined function to convert the CR
character used in Microsoft Excel to the CR character used in Microsoft
Access. To create the function, follow these steps:
- Start Microsoft Access and open any database.
- Create a module and type the following line in the Declarations
section if it is not already there:
- Type the following procedure.
NOTE: In the following sample code, an underscore (_) at the end of a
line is used as a line-continuation character. Remove the underscore
from the end of the line when re-creating this code in Access Basic.
Function ChangeStr (s As Variant, a As String, n As String,_
c As Integer) As Variant
' This function changes all substrings "a" and string "s"
' to "n." The parameter "c" has the same function as in the
' InStr() function.
Dim temp As String, pos As Integer
temp = ""
If IsNull(s) Then
ChangeStr = Null
Exit Function
End If
If a = "" Or s = "" Then
ChangeStr = s
Exit Function
End If
pos = InStr(1, s, a, c)
While pos > 0
temp = temp & Mid$(s, 1, pos - 1) & n
s = Right$(s, Len(s) - pos - Len(a) + 1)
pos = InStr(1, s, a, c)
Wend
ChangeStr = temp & s
End Function
- Create a new update query. Drag the field that you want converted to
the query grid.
- In the Update To row of the query grid, type the following expression:
ChangeStr([<fieldname>],Chr$(10),Chr$(13) & Chr$(10),0)
where <fieldname> is the name of the field that you want to convert.
- Run the query. Note that text containing vertical bars is divided into
separate lines with carriage returns.
REFERENCES
For more information about importing spreadsheet data, search for
"spreadsheets, importing or linking" using the Microsoft Access for
Windows 95 Help Index.
Modification Type: | Minor | Last Reviewed: | 10/11/2006 |
---|
Keywords: | kbinterop kbprb kbProgramming KB115576 |
---|
|