473,890 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Importing only some columns of an excel file to access

68 New Member
I have an excel file that has 15 columns but I only need 4. I need to pull them into an Access table w. VBA.
I need
Column A: Client,
Column C: City, and
Column D: State.
The file will be of variable length.

My problem is that Column B is a phone number field that I don't want and what ever I do I can't avoid my database creating a import errors table for this field.
It contains a variety of numbers and spaces so I whether I have my table set to text or number they all error.
I don't care whether I import all the excel fields, or only the 3 I need, but I need some way to not error on column B.

Is it possible to import only certain columns? If so, does anyone have the code?
I would love the whole thing to be text and use import specs, but that's for TransferText and for excel you need to do TransferSpreads heet.

I have tried looking on the web for the answer, but keep coming across people importing a single range. Thanks!
Jun 11 '11 #1
20 32848
759 Contributor
Just an idea: Copy-Paste the columns you need to another sheet or workbook (in Excel). Then import.
Good luck !
Jun 12 '11 #2
68 New Member
For sure, but it will be run every few days and I'm trying to make it so the users don't need to adjust the import file.
Jun 12 '11 #3
Rekha Kumaran
30 New Member
No prob... Use PHP and extract the data from the excel file and import it into ur DB. If u use cron job, it will do automatically.
Jun 13 '11 #4
32,584 Recognized Expert Moderator MVP
It's interesting/unfortunate that MS don't provide the ability to define an Import/Export Spec for Excel files. It is possible during the manual import to specify columns to avoid, but this can't be saved for automation it seems.

It seems you can do it, but for non-contiguous columns, probably only into separate tables.

I used the following code to handle a duplicate of your situation :

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  4. Public Sub ACD()
  5.     Dim strSQL As String
  6.     Dim db As DAO.Database
  7.     Dim rs As DAO.Recordset
  9.     Call DoCmd.TransferSpreadsheet(acImport, _
  10.                                    acSpreadsheetTypeExcel9, _
  11.                                    "tblData", _
  12.                                    "H:\ProfileName\Access\ImportTest.Xls", _
  13.                                    False, _
  14.                                    "A:A")
  15.     strSQL = "ALTER TABLE [tblData] ADD COLUMN [F2] Text(255)"
  16.     Call CurrentDb.Execute(strSQL)
  17.     strSQL = Replace(strSQL, "[F2]", "[F3]")
  18.     Call CurrentDb.Execute(strSQL)
  19.     Call DoCmd.TransferSpreadsheet(acImport, _
  20.                                    acSpreadsheetTypeExcel9, _
  21.                                    "tblDataTmp", _
  22.                                    "H:\ProfileName\Access\ImportTest.Xls", _
  23.                                    False, _
  24.                                    "C:D")
  25.     Set db = CurrentDb
  26.     With db.TableDefs("tblData").OpenRecordset(dbOpenTable, dbDenyWrite)
  27.         Call .MoveFirst
  28.         Set rs = db.TableDefs("tblDataTmp").OpenRecordset(dbOpenTable)
  29.         Call rs.MoveFirst
  30.         Do Until .EOF
  31.             Call .Edit
  32.             !F2 = rs!F1
  33.             !F3 = rs!F2
  34.             Call .Update
  35.             Call .MoveNext
  36.             Call rs.MoveNext
  37.         Loop
  38.         Call rs.Close
  39.         Call .Close
  40.     End With
  41.     Call db.TableDefs.Delete("tblDataTmp")
  42. End Sub
Clearly, there are potential changes to be made for a more sophisticated result.
Jun 13 '11 #5
12,516 Recognized Expert Moderator MVP
You could import into a temporary table, run an append, and then drop the temporary table.
Jun 13 '11 #6
32,584 Recognized Expert Moderator MVP
My problem is that Column B is a phone number field that I don't want and what ever I do I can't avoid my database creating a import errors table for this field.
It contains a variety of numbers and spaces so I whether I have my table set to text or number they all error.
I don't care whether I import all the excel fields, or only the 3 I need, but I need some way to not error on column B.
That would still error Rabbit. See second paragraph of OP.
Jun 13 '11 #7
12,516 Recognized Expert Moderator MVP
Shouldn't setting that field in the table and spreadsheet to text work? You just need to automate excel to modify the column to text and save before you do the import.
Jun 13 '11 #8
12,516 Recognized Expert Moderator MVP
If it's just the import errors table you're worried about, you can just drop that table if it exists after the import.
Jun 13 '11 #9
32,584 Recognized Expert Moderator MVP
No. It's not as simple as either of those.

Deleting a table that you don't know the name of is a problem and automating Excel is more complicated (even) than importing as separate ranges and merging them together as my code illustrates. Certainly there is no straightforward solution. What I posted was the closest to that I could come up with (though I appreciate it's quite wide of the mark).
Jun 13 '11 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Paul | last post by:
I was wondering if anyone has had an issue where using vba code to read an excel file and import the data into an access table some records are not imported from the excel file. It seems looking at the data in the excel file that if the first character in the excel file cell is numeric it will read and write only numeric values only. If I sort the coloumn in the excel file and the first character in the cell read is alphanumeric then only...
by: Geoff Jones | last post by:
Hi I have a question which I hope somebody can answer. I have written a VB application with which I want to import an Excel file, analyze the data within it and do some calculations. There are in fact five sheets in the Excel file. My original idea was to import the file into access and create a database file; which I did and worked beautifully. It generated five tables in the database as expected. However, I then thought why not...
by: Janelle.Dunlap | last post by:
When I import an Excel file containing hyperlinks into Access, the hyperlinks turn into text and no longer hold their links. I am using the TransferSpreadsheet function in Access to import my table. I have done a bit of searching a come across this code: UPDATE tblTest SET tblTest.hyperdocs = "#" & & "#"; (where tblTest = name of table and hyperdocs = name of hyperlink field in spreadsheet This is supposed to add pound signs...
by: winzy | last post by:
I have a table in Access which needs updating from an Excel file. Instead of importing the whole Excel like a new table in Acess, how do I do a partial import/update?? For example, Access table has 100 rows of records and 10 columns of attributes. The Excel table has only 50 rows of records and and 2 attributes. The key IDs for the 50 rows and names for the 2 attributes are already defined in the Access table. Thanks in advance!!
by: Haas C | last post by:
Hi All! I was wondering if you guys can help with this: I have created an Access database which has a table with identical fields as a tab in an Excel workbook. To update this table (tblClaims), I open it up and delete all rows. Nex, I Import data into the table from Excel (i don't use the Link Tables... function because it corrupted my Excel file last time.) Is there anyway to automate this process? Ideally, I'd like to open the Access...
by: Anish G | last post by:
Hi All, I am getting the below given error while running my application in live server. In my local machine, its working fine. Please help me as it is very urgent for me. Exception from HRESULT: 0x800A03EC Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details:...
by: aoztuncer | last post by:
I can import data from Excel using the following code if the spreadsheet is saved on the computer and has a non-empty path name: string connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + oXL.ActiveWorkbook.Path + "\\" + oXL.ActiveWorkbook.Name + ";" + "Extended Properties=Excel 8.0"; OleDbCommand cmdSelect = new OleDbCommand("SELECT * FROM ", conn); However, if the running instance of Excel is not saved on the computer and has...
by: arshigill | last post by:
I want to import data from excel file inot mysql database table but unable to solve this problem. I have searched google and find an example of importing of CSV excel file. But when I modify it for my own requirements it does not work. Please help me with an example to import data in colums in exel file into mysql table columns. Thank PHP Lover
by: JFKJr | last post by:
I have an excel file, which has columns C and D grouped together, I am trying to delete blank columns and rows from the excel file, ungroup the columns and import the file to MS Access using Access VBA code. The following is the Access VBA code I used to delete blank columns and rows in the excel file. But, unfortunately, the resultant excel file still has two columns (C and D) grouped together, so when I am importing the file to MS Access,...
by: muddasirmunir | last post by:
I want to know how can we Import data from Excel into Excel Using vb6. Any help where can i start ?
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.