Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

asked on

exporting data and filtered data from a subform

exporting data from subform

I have used this code in 2010 and 2003  to export a subform and even if the subform had filtered records, it ONLY exported the filtered data ?

Now it does not in Office 365 ?

DoCmd.DeleteObject acQuery, "qryTemp"
     Set qdf = CurrentDb.CreateQueryDef("qryTemp", Me.All_ExtendedPaymentTerms_subform.Form.RecordSource)
     DoCmd.OutputTo acOutputQuery, "qryTemp", acFormatXLS, "C:\Users\" & Racfid & "\Desktop\All_Extended.xls", True
ASKER CERTIFIED SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Fordraiders

ASKER

Dale,
This worked also:
If Me.Dirty Then Me.Dirty = False

Dim rsClone As DAO.Recordset
'Set rsClone = Me.All_ExtendedPaymentTerms_subform.Form.RecordsetClone
If Me.TabCtl0.Value = 0 Then
    Set rsClone = Me.All_ExtendedPaymentTerms_subform.Form.RecordsetClone
End If
If Me.TabCtl0.Value = 1 Then
    Me.National_Account_View_subform.Form.RecordsetClone
End If
If Me.TabCtl0.Value = 2 Then
  Me.Government_View_subform.Form.RecordsetClone
End If
If Me.TabCtl0.Value = 3 Then
   Me.Commercial_Manufacturing_View_subform.Form.RecordsetClone
End If


If rsClone.EOF Then
MsgBox "No records found."
Set rsClone = Nothing
Exit Sub
End If

    Dim xlApp As Object
    Set xlApp = CreateObject("Excel.Application")
    With xlApp
        .Visible = True
        .Workbooks.Add
        .Sheets("Sheet1").Select
       
        .ActiveSheet.Range("A2").CopyFromRecordset rsClone
       
        For i = 1 To rsClone.Fields.Count
            xlApp.ActiveSheet.Cells(1, i).Value = rsClone.Fields(i - 1).Name
        Next i
        xlApp.Cells.EntireColumn.AutoFit
    End With
thanks dale
glad  I could help.