Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Access Recordset Rows to Excel

I've done a bit of excel object programming but am looking for a good way to
iterate through a MS Access recordset pasting the group header field to a
column then move to the next row before pasting the disired fields to a row
in the Excel sheet and continue pasting the rows until I reach the next
group and then paste that group header and so on. Any ideas? Thanks!
My initial code looks like this:
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim mCatCode As String
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set rstRs = dbPM.OpenRecordset(sqlRS, dbOpenSnapshot)
rstRs.MoveFirst
mCatCode = rstRs!CatCode
Do While rstRs.EOF < True


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Access Recordset Rows to Excel

See below - I will append some code to what you have done. Is CatCode the
group header you are referring to? I will assume so. I will also assume
your recordset is sorted by CatCode; you could sort it with the Sort method
if not. Hope the brief outline below helps get you started:

"Geoff" wrote:

I've done a bit of excel object programming but am looking for a good way to
iterate through a MS Access recordset pasting the group header field to a
column then move to the next row before pasting the disired fields to a row
in the Excel sheet and continue pasting the rows until I reach the next
group and then paste that group header and so on. Any ideas? Thanks!
My initial code looks like this:
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim mCatCode As String
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set rstRs = dbPM.OpenRecordset(sqlRS, dbOpenSnapshot)
rstRs.MoveFirst


' Add to your declarations at the top:
' Dim xlCell as Excel.Range
' Dim OldCatCode as String

' continue your code with:
Set xlCell = xlBook.Worksheets("Sheet1").Range("A1")
OldCatCode = ""
Do While rstRs.EOF < True
mCatCode = rstRs!CatCode
' next line checks for new group header:
If Not(mCatCode = OldCatCode) Then
' if it is a new group, put the group header onto the current row and skip
down:
xlCell.Value = mCatCode
Set xlCell = xlCell.Offset(1,0)
OldCatCode = mCatCode
End If
' Now dump the fields into the row where xlCell is.
' The details depend on your recordset contents; you could do this field by
field, i.e.:
xlCell.Offset(0,1).Range("A1").Value = rstRs.Fields("FieldName").Value
' Or you could use a For Each loop to loop through the fields in the
recordset if there are a lot of them

' Go on to the next record:
rstRx.MoveNext
Loop


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
Find the oldest date in an Access recordset gab1972 Excel Discussion (Misc queries) 3 November 18th 09 06:08 PM
How to populate Excel Range from Access RecordSet? deko[_2_] Excel Programming 6 February 27th 05 03:43 PM
Acquiring a single recordset from Access into Excel Humsel Excel Programming 2 September 1st 04 07:04 AM
Access Recordset with Built-In Function Jeff Huff Excel Programming 3 November 10th 03 10:08 PM
Returning the Number of Rows in a Recordset Alex[_14_] Excel Programming 2 November 1st 03 11:14 AM


All times are GMT +1. The time now is 03:49 AM.

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"