473,856 Members | 2,133 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
20 32845
68 New Member
Shoot! It's definately frusterating that it allows me to set up and save the import specs but not use them in vba!

NeoPa, I'm going to check out your code. Thanks for the reminder that I wouldn't know the name of the file I was going to delele, because I was assuming it was something similar (or started in something similar each time). Would there be any other way to identify the import errors table?
Jun 15 '11 #11
12,516 Recognized Expert Moderator MVP
The import errors table always has the string "$Import_Errors " at the end of it.
Jun 15 '11 #12
32,584 Recognized Expert Moderator MVP
Shoot! It's definately frusterating that it allows me to set up and save the import specs but not use them in vba!
That's a misunderstandin g. Access allows Import/Export specs for Text files (not Excel) and they certainly can be used from VBA. See comment in post #5.
Jun 15 '11 #13
68 New Member
NeoPa, Yes, I was referring to Excel. I think it's strange that I can manually import an excel file, set up import specs, save the specs, but then have no way of using them again.

I know that text files are different and that you can use your specs name in the TransferText function.

I wasn't expecting not to be able to do this. There is no other function to use?

Rabbit, In the meantime while I was waiting for a reponse I ended up setting up something to delete the import table. Thanks for the post I will update it to delete where the end is "$Import_Errors "
Jun 15 '11 #14
32,584 Recognized Expert Moderator MVP
A number of confusions here.
  1. You say you can save Excel import specs. I can't in 2003 (Not for Excel - only for Text). Are you using a later version possibly? If you're using a feature not available to all versions it's necessary to indicate the version in the question (See the various instructions on how to post).
  2. If you are using a version that allows saving of Excel Import specs then I suspect that it is indeed possible to reuse these specs from your code. I have no way for now of testing this out, but I'd be very surprised if it were not so.
  3. You say "In the meantime while I was waiting for a reponse". Did you ever try out the code I included in post #5? There is no direct response to it. It's really down to you to ensure you read all of the replies.

Frankly, if there are saved Excel specs then I'd use them in preference, but if not then the code I posted worked perfectly for me.
Jun 15 '11 #15
68 New Member
Thank you a TON for reading and replying! My tone may have come across less appreciative that I intended!

1. I'm using 2007. You are right that I should state that. It didn't occur to me. Also, I have had some time off from building databases so I don't actually remember what I was doing in previous versions. I'll double check this point, and maybe see if I still have things I've built in the past to get a better handle of what I have and what I've done in the past.
2. I agree which is why I was so confused about it. I'll do more research
3. When I said waiting for a response that had nothing to do with the responders or me not reading them. I'm very interested in what everyone has had to say and read it all. I only meant that I was playing around with it RIGHT after I posted it and that's what I came up with but I was hoping you all had a better solution for me. I copied your code but haven't yet tried it. I am reluctantly deleting the import table since I had already set that up (though incorrectly w/ the table name) before I got your suggestion. I want to check yours out as another/better option, but I have a few more things I need to figure out/build in the next couple of days.
4. In fact, if I haven't gotten a chance to respond sooner, it's becuase I was reading (and bookmarking) some of your other posts! Seriously. :) Forums like these are super helpful.
Thank you!
Jun 16 '11 #16
32,584 Recognized Expert Moderator MVP
I was simply curious. Sometimes people overlook a post when someone else posts before they get a chance to look. Essentially, they work under the assumption that when they are notified a new post is available there is necessarily only one post. It's a mistake, but one that occurs from time-to-time, especially by those not used to working in a forum. I honestly felt this may have happened so was drawing your attention to it. I won't deny it's a good idea for you to respond to all posts in one of your threads, but not everyone does, and I'm generally not too worried about it. In this case I was just worried about the possibility that after all this time you hadn't even noticed it.

In short, your tone was not an issue and thank you for your kind words. I'm very glad that some of my posts can help people looking to learn more about Access or Excel.
Jun 16 '11 #17
68 New Member
I am new to forums and don't have it all figured out (I've ended up clicking on the link to the question to get all the reponses. I don't know how it's supposed to work).

I was actually about to respond to all the posts, but then thought I shouldn't. Thought it might be too much of me. :).
I made a brief reference to your code earlier, but only to say I was going to check it out.

I've encountered the pesky security window in automatically sending emails via outlook and this afternoon I was looking at your outlook automation but didn't know if it took that pesky window into account...
Jun 16 '11 #18
32,584 Recognized Expert Moderator MVP
I made a brief reference to your code earlier, but only to say I was going to check it out.
Of course you did. I overlooked that when I saw the later post. I was getting a bit confused with a bunch of things that didn't seem to make sense, but you're quite right. You did refer to it. That's all that I was looking for really (but I missed it when it was).
I've encountered the pesky security window in automatically sending emails via outlook and this afternoon I was looking at your outlook automation but didn't know if it took that pesky window into account...
You'll have to try it out and see. I've really done very little with Outlook due to exactly that problem. That code was provided by another (very helpful) member (fauxanadu).
Jun 16 '11 #19
12,516 Recognized Expert Moderator MVP
You can get around the Outlook limitations by using the CDO object instead.
Jun 16 '11 #20

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: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
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: 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: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.