Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Importing / Linking / September 2005

Tip: Looking for answers? Try searching our database.

Importing From Excel Using Import Spreadsheet Macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alan - 13 Sep 2005 18:15 GMT
I have tried to import data supplied to me in a spreadsheet which contains
reference to an employee number ... this is in the main a seven digit numeric
value, however there are a number which contain 6 numbers and a letter at the
end ... problem appears to occur when Access reads the data ... assumes all
are numeric and omits the alphanumeric values !

Is there a way when importing data using a macro that you can specify that
employee_no is a text field and should be imported as such ??

Many Thanks in advance
John Nurick - 13 Sep 2005 20:10 GMT
Hi Alan,

There are several ways.

1) One of the best is to prefix each value in Excel with an apostrophe,
e.g. '987654 instead of 987654. This forces Excel to treat the numbers
as text, but the apostrophes don't show up on the worksheet  or get
imported into Access. Here are a couple of VBA procedures that will add
apostrophes to every value in a column, or remove them from the selected
cells.

Sub AddApostrophesAllToColumn( _
     ByVal TheColumn As Long _
 )
 Dim C As Excel.Range
 With ActiveWorkbook.ActiveSheet
   For Each C In Intersect(.Columns(TheColumn), _
       .UsedRange).SpecialCells(xlCellTypeConstants).Cells
     C.Formula = "'" & C.Formula
   Next
 End With
End Sub

Sub RemoveApostrophes()
 Dim C As Excel.Range
 For Each C In Application.Selection.Cells
   C.Formula = C.Formula
 Next
End Sub

2) Sometimes it's enough to ensure that the first value in the column in
question cannot be interpreted as a number. E.g. if the first value is
123456A. Or try creating the table in Access first, with the field types
you need, before importing.

3) For the deep and dirty, see
http://www.dicks-blog.com/excel/2004/06/external_data_m.html
and http://support.microsoft.com/?id=257819

>I have tried to import data supplied to me in a spreadsheet which contains
>reference to an employee number ... this is in the main a seven digit numeric
[quoted text clipped - 6 lines]
>
>Many Thanks in advance

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
Klatuu - 13 Sep 2005 22:39 GMT
Load it into an existing table with the data types specified the way you want
them.

> I have tried to import data supplied to me in a spreadsheet which contains
> reference to an employee number ... this is in the main a seven digit numeric
[quoted text clipped - 6 lines]
>
> Many Thanks in advance
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.