Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Extacting data from Access

Hi All
I have an Access database with around 200,000 rows, this increases by a few
hundred per day. In this database is a column containing the actual date
(dd/mm/yyyy). I wish to open this database from Excel, extract the following
1. The first and last date in the date base ( the Access table is not in
date order)
2. A list of all dates with a count of the number of records

Look forward to your responses

Cheers


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Extacting data from Access

Hi Chris
Great! I had not considered using DAO/ADO as I assumed wrongly the only way
was to use Query.

I will give it a try. Many thanks

Nigel

"Chris Wilkinson" wrote:

hi,

try something like this - you need to add a reference to the DAO library:


Sub extractData()
Dim strSQL As String
Dim app As DAO.DBEngine
Dim db As DAO.Database
Dim rs As DAO.Recordset

Set app = New DAO.DBEngine
Set db = app.OpenDatabase("C:\db1.mdb") ' enter your own info here

' get first date
strSQL = "SELECT min(datefield) from table" ' enter your own info here
Set rs = db.OpenRecordset(strSQL)
Range("a1").CopyFromRecordset rs

' get last date
strSQL = "SELECT max(datefield) from table" 'enter your own info here
Set rs = db.OpenRecordset(strSQL)
Range("b1").CopyFromRecordset rs

' get count of records by date in date order - enter own info below
strSQL = "SELECT COUNT(*) from table GROUP BY datefield ORDER BY
datefield"
Set rs = db.OpenRecordset(strSQL)
Range("a3").CopyFromRecordset rs

rs.Close
db.Close

Set rs = Nothing
Set db = Nothing
Set app = nothing

End Sub

you can do it with ADO as well but this will work fine

Chris


"Nigel RS" wrote:

Hi All
I have an Access database with around 200,000 rows, this increases by a few
hundred per day. In this database is a column containing the actual date
(dd/mm/yyyy). I wish to open this database from Excel, extract the following
1. The first and last date in the date base ( the Access table is not in
date order)
2. A list of all dates with a count of the number of records

Look forward to your responses

Cheers


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Extacting data from Access

Sorry, I should have put for that part
strSQL = "SELECT datefield, Count(*) from table GROUP BY datefield " & _
" ORDER BY datefield"

"Nigel RS" wrote:

hi Chris
That works!

I get the count by date, but not the actual date for the count.

Is there anyway I can show both the DATE in column 1 and and the COUNT in
column 2

Cheers


"Chris Wilkinson" wrote:

hi,

try something like this - you need to add a reference to the DAO library:


Sub extractData()
Dim strSQL As String
Dim app As DAO.DBEngine
Dim db As DAO.Database
Dim rs As DAO.Recordset

Set app = New DAO.DBEngine
Set db = app.OpenDatabase("C:\db1.mdb") ' enter your own info here

' get first date
strSQL = "SELECT min(datefield) from table" ' enter your own info here
Set rs = db.OpenRecordset(strSQL)
Range("a1").CopyFromRecordset rs

' get last date
strSQL = "SELECT max(datefield) from table" 'enter your own info here
Set rs = db.OpenRecordset(strSQL)
Range("b1").CopyFromRecordset rs

' get count of records by date in date order - enter own info below
strSQL = "SELECT COUNT(*) from table GROUP BY datefield ORDER BY
datefield"
Set rs = db.OpenRecordset(strSQL)
Range("a3").CopyFromRecordset rs

rs.Close
db.Close

Set rs = Nothing
Set db = Nothing
Set app = nothing

End Sub

you can do it with ADO as well but this will work fine

Chris


"Nigel RS" wrote:

Hi All
I have an Access database with around 200,000 rows, this increases by a few
hundred per day. In this database is a column containing the actual date
(dd/mm/yyyy). I wish to open this database from Excel, extract the following
1. The first and last date in the date base ( the Access table is not in
date order)
2. A list of all dates with a count of the number of records

Look forward to your responses

Cheers


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Extacting data from Access

hi Chris
That works!

I get the count by date, but not the actual date for the count.

Is there anyway I can show both the DATE in column 1 and and the COUNT in
column 2

Cheers


"Chris Wilkinson" wrote:

hi,

try something like this - you need to add a reference to the DAO library:


Sub extractData()
Dim strSQL As String
Dim app As DAO.DBEngine
Dim db As DAO.Database
Dim rs As DAO.Recordset

Set app = New DAO.DBEngine
Set db = app.OpenDatabase("C:\db1.mdb") ' enter your own info here

' get first date
strSQL = "SELECT min(datefield) from table" ' enter your own info here
Set rs = db.OpenRecordset(strSQL)
Range("a1").CopyFromRecordset rs

' get last date
strSQL = "SELECT max(datefield) from table" 'enter your own info here
Set rs = db.OpenRecordset(strSQL)
Range("b1").CopyFromRecordset rs

' get count of records by date in date order - enter own info below
strSQL = "SELECT COUNT(*) from table GROUP BY datefield ORDER BY
datefield"
Set rs = db.OpenRecordset(strSQL)
Range("a3").CopyFromRecordset rs

rs.Close
db.Close

Set rs = Nothing
Set db = Nothing
Set app = nothing

End Sub

you can do it with ADO as well but this will work fine

Chris


"Nigel RS" wrote:

Hi All
I have an Access database with around 200,000 rows, this increases by a few
hundred per day. In this database is a column containing the actual date
(dd/mm/yyyy). I wish to open this database from Excel, extract the following
1. The first and last date in the date base ( the Access table is not in
date order)
2. A list of all dates with a count of the number of records

Look forward to your responses

Cheers


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Extacting data from Access

hi,

try something like this - you need to add a reference to the DAO library:


Sub extractData()
Dim strSQL As String
Dim app As DAO.DBEngine
Dim db As DAO.Database
Dim rs As DAO.Recordset

Set app = New DAO.DBEngine
Set db = app.OpenDatabase("C:\db1.mdb") ' enter your own info here

' get first date
strSQL = "SELECT min(datefield) from table" ' enter your own info here
Set rs = db.OpenRecordset(strSQL)
Range("a1").CopyFromRecordset rs

' get last date
strSQL = "SELECT max(datefield) from table" 'enter your own info here
Set rs = db.OpenRecordset(strSQL)
Range("b1").CopyFromRecordset rs

' get count of records by date in date order - enter own info below
strSQL = "SELECT COUNT(*) from table GROUP BY datefield ORDER BY
datefield"
Set rs = db.OpenRecordset(strSQL)
Range("a3").CopyFromRecordset rs

rs.Close
db.Close

Set rs = Nothing
Set db = Nothing
Set app = nothing

End Sub

you can do it with ADO as well but this will work fine

Chris


"Nigel RS" wrote:

Hi All
I have an Access database with around 200,000 rows, this increases by a few
hundred per day. In this database is a column containing the actual date
(dd/mm/yyyy). I wish to open this database from Excel, extract the following
1. The first and last date in the date base ( the Access table is not in
date order)
2. A list of all dates with a count of the number of records

Look forward to your responses

Cheers


Reply
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
Can Excel access data from Access?! Al Excel Discussion (Misc queries) 5 April 5th 08 03:52 PM
How do I access the access data via Excel 2002 with auto update ? karthik Excel Programming 1 February 9th 07 01:56 PM
Importing data from Access to Excel, but I need to vary the table from Access Liz L. Excel Programming 3 June 6th 06 02:12 AM
Calculate data from Access and return to Access Mary Fran Excel Programming 0 January 17th 06 02:10 PM
Access data -work in Excel- save in Access s_u_resh Excel Programming 1 October 25th 04 12:52 PM


All times are GMT +1. The time now is 03:50 PM.

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

About Us

"It's about Microsoft Excel"