Exporting data from access form to excel

jeday_jey

New member
Local time
Today, 12:54
Joined
Nov 8, 2007
Messages
4
Hi folks.

I'm new member this site.I have a problem my access project and I have request help you.

My problem. My project has two table and two form .Order (Main Table&Main Form) and Order_Subform (Sub Table&Sub Form) When i click 'Send to Excel' button in Order form it's sending data to Excel file Order.xls but it's only sending one line in order_subform to Excel Order.xls. it is not sending other line. I hope, could I able to explain my concern

Kind Regards.
 

Attachments

I think you could benefit from this function:
Code:
Public Sub CreateSpreadsheetFromRS(rst As Recordset, blnVisible As Boolean, Optional blnHeader As Boolean = True)
' Export Recordset to excel. Guus2005 - 2007
    
    Dim appExcel  As Excel.Application
    Dim wbExcel   As Workbook
    Dim wsExcel   As Worksheet
    Dim qdf       As QueryDef
    Dim intRij    As Integer
    Dim intVelden As Integer
    Dim intTeller As Integer
        
    intRij = 0
    
    If rst.EOF Then
        MsgBox "Geen records gevonden voor " & rst.Name, vbExclamation, Application.Name
        Exit Sub
    End If
    
    Set appExcel = New Excel.Application
    With appExcel
        .Visible = blnVisible
        Set wbExcel = .Workbooks.Add
        Set wsExcel = wbExcel.Worksheets(1)
    End With
    
    intVelden = rst.Fields.Count - 1
            
    If blnHeader Then 'Default header fieldnames
        intRij = intRij + 1
        For intTeller = 0 To intVelden
            wsExcel.Cells(intRij, intTeller + 1) = rst.Fields(intTeller).Name
        Next intTeller
    End If
                
    Do While Not rst.EOF
        intRij = intRij + 1
        For intTeller = 0 To intVelden
            If intTeller = 0 Then
                wsExcel.Cells(intRij, intTeller + 1) = rst.Fields(intTeller)
            ElseIf IsNumeric(rst.Fields(intTeller)) Then
                wsExcel.Cells(intRij, intTeller + 1) = CDbl(rst.Fields(intTeller)) / 1000
            Else
                wsExcel.Cells(intRij, intTeller + 1) = rst.Fields(intTeller)
            End If
        Next intTeller
        rst.MoveNext
    Loop
        
    wsExcel.Columns.AutoFit
    
    wsExcel.Range("B4:F34").Style = "Comma"
    wsExcel.Range("B4:F34").NumberFormat = "_-* #,##0_-;_-* #,##0-;_-* ""-""??_-;_-@_-"
    
    Set rst = Nothing
    Set qdf = Nothing

End Sub
It requires a recordset and writes it to a new spreadsheet.

Enjoy!
 

Users who are viewing this thread

Back
Top Bottom