Solved

Daily Reports in Access - auto import data and prompt for date range

Posted on 2006-11-01
3
370 Views
Last Modified: 2008-03-10
Every morning I need to download data from a website. The data comes in the form of an Excel spreadsheet and shows the previous day's orders.

I created an Excel macro that I run each time I open these "raw" Excel files. The macro formats some columns and does general clean-up.

Next, I import the spreadsheet into Access, but here's the part that is rather tedious (and i'm sure there's a better way to do it)

I wrote a report that is based on a QUERY, and the query is based on a specific TABLE.
The table is named "AM".
Since the query is based on the table named, specifically, "AM", I have to make sure that the Excel file is ALWAYS imported into a new table called "AM"

I take the previous day's "MA" table and rename it "MA_2006_10_14" for example, and then import the new Excel file into a new table called "AM"
I do this day after day.

Here's what I'd like to do instead:

1. Assuming the daily Excel file ALWAYS has the same file name, and is ALWAYS saved in the same directory, I'd like to have a button in Access that will automatically import whatever is in that Excel file and APPEND it to the current "AM" table. (no more renaming yesterday's table and then creating a new one over and over ... I'd like to keep appending each day's data to yesterday's table.)

2. Next, when I run the report, I want to be promted "Enter Start Date" and then "Enter End Date". Since the table will keep getting appended (i.e. keep growing) I can control what data shows on the report by specifying a date range. (The table might have 30 days of orders but I only want to see the orders placed on October 14th, for example)

Any help would be much appreciated!!
0
Comment
Question by:ecarbone
3 Comments
 
LVL 9

Assisted Solution

by:mpmccarthy
mpmccarthy earned 250 total points
ID: 17853955
The TransferSpreadsheet command in the macro will do this for you or using code

Put this in the command button on click event:

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel3, "AM", "Full path to file", True


For the run report event.  Go to the query that is the recordsource of the report and in the criteria line under the date field put

BETWEEN [Enter Start Date:] AND [Enter End Date:]
0
 
LVL 2

Accepted Solution

by:
Deb8stud earned 250 total points
ID: 17853992
Make sure you have a table called 'Temp' with the exact same structure as AM and your spreadsheet except for the aditional field called 'Date'.  Use this code to append your records:

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Temp", YourFileNameHere, True
DoCmd.RunSQL "INSERT INTO AM ( [DateFieldName] ) SELECT Temp.*, Date() as Expr1 FROM Temp;"

Then, use the following code in the Report_Open event:

Dim BegDate As Date
Dim EndDate As Date

BegDate = CDate(InputBox("Beginning Date:", "Report Parameters", Date))
EndDate = CDate(InputBox("Ending Date:", "Report Parameters", Date))

Me.FilterOn = True
Me.Filter = "Date Between #" & BegDate & "# and #" & EndDate & "#"


Let me know if this works.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HasData 9 38
Omit Values from a Combo Box in access 2 10
can't find file error on web browser 1 17
tabctrl with page click event 9 12
This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now