473,739 Members | 2,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Importing Multiple Excel Files Into Access

13 New Member
I get a daily excel file for a entire month which I want to transfer into Access at the end of the month. So, there are around 20-25 excel files I get by the end of the month, and I would like to import them into Access using a button. The data contained in the excel files is similar, so there should no formatting issues while importing.

I searched through the forums and found the code by mmccarthy for importing excel files. I tried using that code, but it keeps giving me a error message "No files found"
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command3_Click()
  2. Dim strFile As String 'Filename
  3. Dim strFileList() As String 'File Array
  4. Dim intFile As Integer 'File Number
  5. Dim filename As String
  6. Dim path As String
  7.  
  8.   DoCmd.SetWarnings False
  9.   path = "C:\Documents and Settings\KK\Desktop\Test\"
  10.  
  11.   'Loop through the folder & build file list
  12.   strFile = Dir(path & "*.xls")
  13.  
  14.   While strFile <> ""
  15.      'add files to the list
  16.      intFile = intFile + 1
  17.      ReDim Preserve strFileList(1 To intFile)
  18.      strFileList(intFile) = strFile
  19.       strFile = Dir()
  20.   Wend
  21.  
  22.   'see if any files were found
  23.   If intFile = 0 Then
  24.     MsgBox "No files found"
  25.   End If
  26.  
  27.   'cycle through the list of files
  28.   For intFile = 1 To UBound(strFileList)
  29.     filename = path & strFileList(intFile)
  30.     DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel3, "tblClientMail", filename, True
  31.   Next intFile
  32.  
  33.   DoCmd.SetWarnings True
  34.  
  35. End Sub
  36.  
Can someone tell me what I might be doing wrong ??

Thanks.
May 17 '07 #1
28 19249
MMcCarthy
14,534 Recognized Expert Moderator MVP
So all these *.xls files are sitting in a folder called test on your desktop?
May 17 '07 #2
puppydogbuddy
1,923 Recognized Expert Top Contributor
Try placing the wildcard symbol in your last subdirectory in your file path:


path = "C:\Documen ts and Settings\KK\Des ktop\Test\*.*"
May 17 '07 #3
kkadakia
13 New Member
mmccarthy - Yes, all these .xls files on my desktop in a folder named Test. I had deleted the line Exit Sub below the MsgBox. Was that the correct thing to do ?

puppydog - I tried that, but still tells me No files found. When I then click on Ok, it tells me Run-time error '9': Subscript out of range. When I click on debug, it takes me to this line in the code - For intFile = 1 To UBound(strFileL ist)

Thanks.
May 17 '07 #4
MMcCarthy
14,534 Recognized Expert Moderator MVP
mmccarthy - Yes, all these .xls files on my desktop in a folder named Test. I had deleted the line Exit Sub below the MsgBox. Was that the correct thing to do ?

puppydog - I tried that, but still tells me No files found. When I then click on Ok, it tells me Run-time error '9': Subscript out of range. When I click on debug, it takes me to this line in the code - For intFile = 1 To UBound(strFileL ist)

Thanks.
Set a breakpoint on line14 in the example. When the code breaks mouse over the strFile variable and see what value it contains.
May 17 '07 #5
kkadakia
13 New Member
I am not sure if this is what u wanted. But after creating the breakpoint, it tells me strFile = ""

How do i check the strFile variable value ?
May 17 '07 #6
MMcCarthy
14,534 Recognized Expert Moderator MVP
I am not sure if this is what u wanted. But after creating the breakpoint, it tells me strFile = ""
Now with the same breakpoint mouse over path and see if it is set to where you think?

Next go to your desktop and open the test folder. Right click on any of the *.xls files and go to properties. Check the Location. Make sure it letter for letter corresponds to the path in your file.

Lastly are you sure these files have an *.xls extension.
May 17 '07 #7
kkadakia
13 New Member
Now with the same breakpoint mouse over path and see if it is set to where you think?

Next go to your desktop and open the test folder. Right click on any of the *.xls files and go to properties. Check the Location. Make sure it letter for letter corresponds to the path in your file.

Lastly are you sure these files have an *.xls extension.
When taking the mouse the path, it is exactly where i want to select the excel files from.

The properties of the folder also shows the same location.

All the files do have a .xls extension.


When my code breaks down, and i click on debug, it points to For intFile = 1 To UBound(strFileL ist)
May 17 '07 #8
MMcCarthy
14,534 Recognized Expert Moderator MVP
When taking the mouse the path, it is exactly where i want to select the excel files from.

The properties of the folder also shows the same location.

All the files do have a .xls extension.


When my code breaks down, and i click on debug, it points to For intFile = 1 To UBound(strFileL ist)
Thats because you removed the End Sub. The code is continuing without any files available.

There doesn't seem to be any problem with the code I don't understand why the files can't be found.
May 17 '07 #9
kkadakia
13 New Member
Thats because you removed the End Sub. The code is continuing without any files available.

There doesn't seem to be any problem with the code I don't understand why the files can't be found.
So do i need to put the EndSub back ?

Also, i am using Access 07, though it is saved as Access 03. Could that be a issue ?
May 17 '07 #10

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

Similar topics

11
3418
by: Grim Reaper | last post by:
I am importing a .csv file into Access that has 37 fields. My problem is that sometimes the last field only has data at the end of the column (it looks like when you import a file into Access, for the last field, it only checks the top few 'cells' to see if there is any data, if not, the field is not imported). How do I 'force' Access to import the field, regardless if there is data in the top of the field or not? For instance, I might...
1
2458
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...
2
3184
by: Snozz | last post by:
The short of it: If you needed to import a CSV file of a certain structure on a regular basis(say 32 csv files, each to one a table in 32 databases), what would be your first instinct on how to set this up so as to do it reliably and minimize overhead? There are currently no constraints on the destination table. Assume the user or some configuration specifies the database name, server name, and filename+fullpath. The server is SQL...
5
3176
by: hharriel | last post by:
Hi, I am hoping someone can help me with an issue I am having with excel and ms access. I have collected data (which are in individual excel files) from 49 different school districts. All districts have used the same excel template and populated the same 32 data fields (columns). I created one large excel file from all 49 files which gives me a master table of 60,000 or so records. I have tried to import this master table into access...
3
3353
by: mukeshsrivastav | last post by:
dear sir i want to move form excel to access. i have 5 excel file having same formats and fields.now i want to import all data in one access table. importing one file is easy .but importing and appending second file in last of the access table created earlier by importing data. thanks .plz help me.
1
5163
by: thadson | last post by:
Hi, I'm trying to import specific cells from MS Excel 2000 spreadsheets to MS Access 2000 tables then move the spreadsheets to a different directory. I'm very new to this and I'm having trouble to implement this. I have worked out so far the code to import certain cells into 1 table, but I do not know how to import some other cells into another tables so the data would be connected and remain together. So lets say that I have 2 tables...
2
4452
by: ciaran.hudson | last post by:
Hi I have multiple excel files of the same format in a directory. They are called book1.xls, book2.xls, book3.xls and so on. What is the easiest way to import the tab named sheet1 from each of the excel files to a databse using SQL server 2000 enterprise edition? Regards, Ciarán
4
7356
by: Harshe | last post by:
hello all, I am trying to code, but i am just stuck after importing one sheet. so here is the gist of what i need help with. In a workbook at the start of the year (january) i will have 4 sheets and these sheets will keep increasing to 12 when the month is december. so i want is, sheet 1 (named abc) should go into table 1 (named abc), sheet 2 (named def)should go into table 2 (named def), sheet 3 (named xyz) should go into table 3 (named...
0
8792
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,...
0
9479
Oralloy
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...
0
9337
jinu1996
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...
1
9266
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,...
0
9209
tracyyun
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...
0
8215
agi2029
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...
0
6054
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();...
0
4826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2193
bsmnconsultancy
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.