473,769 Members | 7,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Searching Multiple Excel Files & Printing Report in MS Access-Is this possible?

15 New Member
Hello Guys,

I have a challenge here and would really appreciate some help. I have customer bills that are all done in excel with a template and stored in directories by month order. At the end of the month or periodically, I need to query and print a report giving customer name, account number, date of service and cost for a particular service/item for all customers who received such a service/item (at times up to 300 customer bills in excel format will be present in the directory). Is it possible to write a script either in access or excel that will search all the files in the directory and prepare such a report? Searching each individual file and having to type or cut and paste the details each time the report is required is quite tedious. This information is stored in the same cell in each bill as a template is used. Does anyone have any idea how to work around this?

Stephen
Jan 17 '08 #1
7 4076
sierra7
446 Recognized Expert Contributor
Hi Stephan

Nobody seems to have answered this so I am replying to say there is somebody out here!

I understand from your description that you have a separate worksheet for each customer bill. This is a nightmare scenario (which is probably why nobody has replied!), so my first suggestion is why don't you write a new app in Access and start over!?!

Nevertheless, just listing the steps I would take to build such an app;-
You need a database with at least one table to recieve the data.
You will need a form which needs a field for the location of the latest folder, assuming you can enter this at the end of a month and then click to run a procedure to import the data. You could add a Common Dialog box to help browse and find this folder.
You need to write a procedure which will loop through the files in the folder. As a start I would just display each file name in a message box to ensure they were being read. You can use the Dir() function recursively (loop untill Dir = "", read Help on Dir Function) and it will find the next file, next file etc..
Once I was sure I was finding each file I would try opening it. The following 'snippets' could probably be used in your program

Expand|Select|Wrap|Line Numbers
  1. Dim xcel As Object
  2.     Set xcel = CreateObject("Excel.Application")
  3.  
  4. 'Open spreadsheet, 
  5.     xcel.workbooks.Open "NextFileName"
  6.     xcel.Visible = False
  7.  
  8. 'Select Sheet    
  9.     xcel.Sheets("Sheet1").Select
  10.  
  11. ' Read data from cells into fields of recorset
  12.     !CustName = xcel.Range("A2").Value
  13.     !AccNo = xcel.Range("C3").Value
  14.     !ODate = xcel.Range("D4").Value
  15.     'etc
NextFileName would be the full path + filename including .wks to the current spreadsheet.
You would need to setup a recordset outside the loop and open it so you can write data to the fields you require. (I have not shown setting up the recordset but !CustName is obiously the field for the Customer Name in the recordset you are using)
"A2","C3", "D4" are just my arbitary names for the cells in the spreadsheet template that hold the data you require to extract.

I have not attempted to write the loops, within loops, within loops that are needed for this exercise but having given it a bit of thought it is quite 'do-able' (which is more than I thought at the begining)

I hope this helps a little !

S7
Jan 20 '08 #2
Stephenoja
15 New Member
Thanks Sierra. Its quite a tall order but I'm trying it out. Having loads of difficulties but I think I am getting thorough. Yes it would have really been better in access but these are files that were already created in microsof excel for the past six years so this confusion is all i have to work with.
Feb 18 '08 #3
ADezii
8,834 Recognized Expert Expert
The following code, although not Optimized, will do exactly what you are requesting, except for the simple part of running a Query against the final Table results (tblCustomerInf o). It actually works quite well on several Excel Spreadsheets but I have no idea how it will perform on 300+. Rather than going into prolonged explanations, I'll simply post the code along with some assumptions, and should you have any questions, please feel free to ask. These assumptions are critical, follow them exactly:
  1. Assumptions
    1. All your Excel Spreadsheets reside in the C:\Customers Directory as in C:\Customers\Cu stomer John Doe.xls.
    2. In each Spreadsheet, the data resides in a consistent location, in this case Customer Name is in Cell "A1", Account Number is in Cell "B1", and Order_Date is in "C1".
    3. tblCustomerInfo (create it) with Fields [Name], [Account#], and [Order_Date].
Expand|Select|Wrap|Line Numbers
  1. Dim strPath As String, appExcel As Excel.Application, strFolderPath As String
  2. Dim MyDB As DAO.Database, MyRS As DAO.Recordset, strSQL As String
  3.  
  4. DoCmd.SetWarnings False
  5.   strSQL = "Delete * From tblCustomerInfo;"
  6.   DoCmd.RunSQL strSQL
  7. DoCmd.SetWarnings True
  8.  
  9. Set MyDB = CurrentDb()
  10. Set MyRS = MyDB.OpenRecordset("tblCustomerInfo", dbOpenDynaset)
  11.  
  12. strFolderPath = "C:\Customers\"
  13. strPath = "C:\Customers\*.xls"     'Set the path.
  14.  
  15. strPath = Dir(strPath, vbNormal)   'Retrieve the first entry.
  16. Set appExcel = CreateObject("Excel.Application")
  17.  
  18. Do While strPath <> ""    'Initiate the loop
  19.   appExcel.Workbooks.Open strFolderPath & strPath
  20.   appExcel.Visible = False
  21.   appExcel.Sheets("Sheet1").Select
  22.     With MyRS
  23.       .AddNew
  24.         !Name = appExcel.Range("A1").Value
  25.         ![Account#] = appExcel.Range("B1").Value
  26.         ![Order_Date] = appExcel.Range("C1").Value
  27.       .Update
  28.     End With
  29. strPath = Dir           'Next entry
  30. Loop
  31.  
  32. appExcel.Quit
  33. Set appExcel = Nothing
  34.  
  35. MyRS.Close
  36. Set MyRS = Nothing
  37.  
  38. MsgBox "This loooooong process has completed!"
  39.  
SAMPLE OUTPUT (tblCustomerInf o):
Expand|Select|Wrap|Line Numbers
  1. ID    Name            Account#       Order_Date
  2. 10    Customer 1    123467         1/23/2008
  3. 11    Customer 2    91023556Y55     4/23/2008
  4. 12    Customer 3    HGT5543FR     11/29/2008
  5.  
Feb 19 '08 #4
ADezii
8,834 Recognized Expert Expert
For my own curiosity, and to further assist you, I ran my code on 3 separate trials against 50 Excel Spreadsheets, the results are as follows:
Expand|Select|Wrap|Line Numbers
  1. 145.10 seconds ==> 2.42 minutes
  2. 144.03 seconds ==> 2.40 minutes
  3. 151.03 seconds ==> 2.52 seconds
  4.  
  5. Average Process Time for 3 Trials : 2.45 minutes
The code ran without a hitch. On 300+ Spreadsheets, I would start the process go out to lunch, and when you returned it should be finished. If you are going to use this approach, let me know since there are a few things that I would like to point out, and the code itself can probably be improved.
Feb 19 '08 #5
sierra7
446 Recognized Expert Contributor
Nice one ADenzii !

What have you got loaded in References to allow you to
Expand|Select|Wrap|Line Numbers
  1.  Dim appExcel As Excel.Application
I have to create OBJECT then set the Object to Excel.Applicati on as two lines.

S7
Feb 20 '08 #6
ADezii
8,834 Recognized Expert Expert
Thanks sierra7, the Reference is to:
Expand|Select|Wrap|Line Numbers
  1. Microsoft Excel XX.X Object Library
Feb 20 '08 #7
sierra7
446 Recognized Expert Contributor
Duh!!
Thanks! I had a reference to Office loaded which obviously didn't work.
S7
Feb 20 '08 #8

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

Similar topics

1
21522
by: Carl Corcoran | last post by:
I'm developing a website for work that exports some reports to excel. I am using the... Response.AddHeader "Content-Disposition","attachment;filename=report.xls" Response.ContentType = "application/vnd.ms-excel" ....strategy to do this. It works wonderfully except I cannot figure out how to do two things: 1) specify a name for the worksheet that's exported (it names the
0
1319
by: Oded | last post by:
Hi, I'm trying to export an ASP based report to Excel while preserving its display properties. I've added: Response.ContentType="application/vnd.ms-excel", and it works fine for several clients. For other clients it displays an emptry excel sheet. I'm not sure, but i think it has something to do with the excel version installed on clients - empty sheets were displayed for Excel 2000 clients while clients running Excel 2002 displayed the...
0
8683
by: Chris Powell | last post by:
I am using Excel/Access 2000 and have two large Excel files (25,000 rows each) that I wish to create linked tables in Access rather than importing into Access. The two source Excel files change frequently, so I want to: A) prompt the user, using a custom form, for the specific Excel files to be linked; B) create the links dynamically; C) insert the linked tables into a select query grid and include the SQL statement in the VBA...
2
4565
by: Sigurd Bruteig | last post by:
Hi all! I have a problem printing multiple reports. The code i use is: Dim stDocName As String stDocName = "rptInvoice" DoCmd.OpenReport stDocName, acNormal, , " = date()" The problem is that invioce details is printed several times on the same invoice and only the first page is shown as first page, even if all reports have only one page. I gess I have to loop trough the code, but I can't figure out how to.
5
1775
by: jayjay | last post by:
I'm trying to help a friend setup a database to track resumes. The candidates will submit their resume in a Word doc format, and I'd like to make a search that will do a context search of the word files and generate a report that matches the keyword search. How would you do something like this in access?
8
3969
by: Hank Reed | last post by:
Hello, I have searched through dozens of old responses to this question but have been unable to make it work in my situation. I'm using Access 2000 We have a very old sticker printer on a serial line. Neither situation is going to be upgraded so don't suggest that. A simple sticker report takes 10 seconds to reach the printer. That is not an issue for me. But, if I want 5 copies of the same sticker, most methods I have tried...
3
2723
by: greatsky | last post by:
Hello- I need to create multiple PDF files from one access report that breaks on client for approx. 20 clients. Any suggestions? Thanks!
3
9700
by: yovation | last post by:
Hi, I have a 3 table database. 1 parent 1 child 1 child of child I would like to get the data into excel as 1 sheet (similar to a grouped report).
1
6198
by: CF FAN | last post by:
Can Report Builder Export Excel Files with multiple Sheets How can I create a report that it can export in excel by multiple
7
7239
by: ivancycheng | last post by:
I have around 400 excel files with same format (multiple sheets) and wants to import few sheets from excel to MS Access (XP version) for further processing. any one can advise me how to do it? (I'm very new in using VB). Many Thanks!
0
9423
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
10219
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
10049
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
9998
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
9865
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
6675
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();...
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.