?
Solved

Export a DAO recordset to excel?

Posted on 2000-04-25
4
Medium Priority
?
1,028 Views
Last Modified: 2011-10-03
How to easily export a DAO recordset to EXCEL within a few line of code?
0
Comment
Question by:mr_anusorn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2750500
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2750975
Use the CopyFromRecordset method.

gobjExcel.Sheets("Budget").Range("E10").CopyFromRecordset rst
0
 
LVL 4

Accepted Solution

by:
CraigLazar earned 300 total points
ID: 2752156
Hi try this this is a sample from one of my projects


be sure to click the referenece ExcelCtl type library in your project refrences of your project

Private Sub cmdSendExcelex_Click()
On Error GoTo eh:
 
  Dim tmpStartDate As Date
  Dim tmpEndDate As Date
 
 
  Dim xl As New Excel.Application
  Dim wb As Excel.Workbook
  Dim ws As Excel.Worksheet
  Dim tmpPercentCheck As String
 
  tmpStartDate = GetStartDate()
  tmpEndDate = GetEndDate()
 
  Dim db As Database
  Dim rsRead As Recordset
  Dim SQLRead As String
  Dim tmpCounter As Integer
 
  'Variables for the cells
    Dim tmpACell As String
    Dim tmpBCell As String
    Dim tmpCCell As String
    Dim tmpDCell As String
    Dim tmpECell As String
    Dim tmpFCell As String
    Dim tmpGCell As String
    Dim tmpHCell As String
 
    SQLRead = "Select * from Expenses where Date >= #" & tmpStartDate & "# and Date<=#" & tmpEndDate & "#;"
    tmpCounter = 0
    Set wb = xl.Workbooks.Open("c:\jimauto\Invoices.xls")
    Set ws = wb.Sheets("List Expenses")
     
    Set db = OpenDatabase("c:\Jimauto\Vat.mdb")
    Set rsRead = db.OpenRecordset(SQLRead, dbOpenSnapshot)
    If rsRead.RecordCount <> 0 Then
        tmpCounter = tmpCounter + 4
        rsRead.MoveFirst
        ws.Range("D1").Value = tmpStartDate
        ws.Range("F1").Value = tmpEndDate
        Do Until rsRead.EOF
            tmpCounter = tmpCounter + 1
            tmpACell = "A" & tmpCounter
            tmpBCell = "B" & tmpCounter
            tmpCCell = "C" & tmpCounter
            tmpDCell = "D" & tmpCounter
            tmpECell = "E" & tmpCounter
            tmpFCell = "F" & tmpCounter
           
            ws.Range(tmpACell).Value = rsRead("Date")
            ws.Range(tmpBCell).Value = rsRead("Company")
            ws.Range(tmpCCell).Value = rsRead("Memo")
            ws.Range(tmpDCell).Value = rsRead("Cost")
            ws.Range(tmpECell).Value = rsRead("Vat")
            ws.Range(tmpFCell).Value = rsRead("Total")
            rsRead.MoveNext
        Loop
            wb.Close SaveChanges:=True
            xl.Quit
            Set xl = Nothing
   
    End If
   
    MsgBox "finnished"
       
eh:
    If Err.Number = 1004 Then
        MsgBox "Excel File is open in excel on the server"
        Exit Sub
    End If

End Sub

hope this helps

:)
Craig
0
 
LVL 1

Expert Comment

by:mathies
ID: 2752966
Transfert you recordset into a array.
After you can directly transfer you array into Excell
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month9 days, 15 hours left to enroll

762 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