LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default How to do an Access Database Query in Excel

Thanks once again Jamie, not much knowledge of Access and I can find my way
around (recorded) Excel code.

Your suggestions is that I create a procedure within the Access database and
simple call this procedure from within an Excel macro

The columns of Data I import from Access are -
StoreNo, SalesDate, Item, MenuLookupName, Sold and these are all taken from
the following location / table "E:\History`.tblSalesMixHistory
tblSalesMixHistory"

I can't test for a couple of days, but will let you know

Thanks

"Jamie Collins" wrote in message
om...
John wrote ...

This is the Macro I've recorded to do exactly what
I manually do to extract the information.


Just like the macro recorder writes awful code, the MS Query wizard
writes lousy SQL. Both should be give a sanity check before going into
production.

Before it exports to Excel I wish it to SUM by Location
each Item sales, so not sure where I would put that in
the code below.


I thought I answered this in my last post. You may want to use the
GROUP BY syntax I suggested. You'd replace the existing SELECT query
with my amended syntax. I'm not sure what your columns are (have they
changed since your original post?) because you haven't given any
schema information and I haven't tested because you didn't supply any
sample data. As a guess:

.CommandText = "SELECT StoreNo, Item, SUM(Sold) AS Sold" & _
" FROM tblSalesMixHi WHERE SalesDate Between" & _
" #31 MAY 2004# And #27 JUN 2004# GROUP BY StoreNo," & _
" Item ORDER BY StoreNo"

Of course, to do this 'properly', you'd create a procedure on the
server (database) and pass it the date parameters e.g. your command
text should be as simple as:

.CommandText = "EXEC MyStoredProc '31 MAY 2004'', '27 JUN 2004'

To achieve this, run something like this on the database server e.g.
in a new blank Query object in MS Access:

CREATE PROCEDURE
MyStoredProc (
start_date DATETIME,
end_date DATETIME
)
AS
SELECT
StoreNo, Item, SUM(Sold) AS Sold
FROM
tblSalesMixHi
WHERE
SalesDate
BETWEEN start_date AND end_date
GROUP BY
StoreNo, Item
ORDER BY
StoreNo
;

Jamie.

--



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel query to access database Piotr Excel Discussion (Misc queries) 3 April 22nd 10 10:23 AM
Database query to import from Access to Excel David T Excel Discussion (Misc queries) 0 August 31st 06 07:12 PM
connect to access database and run a query in excel VBA Bob Excel Discussion (Misc queries) 0 April 25th 06 08:12 PM
Query a Access database that has a module from Excel Oggie Excel Discussion (Misc queries) 1 January 4th 05 08:43 AM
How to use a Access Query that as a parameter into Excel database query Karen Middleton Excel Discussion (Misc queries) 1 December 13th 04 07:54 PM


All times are GMT +1. The time now is 08:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"