简体   繁体   中英

Export Access form into same excel sheet as exported subform

I have a form with a subform in a datasheet view which and I would like them both to be exported into same excel file.

I am exporting the subform using this code I found, which works great but I would like to add to it the main form data as well.

Private Sub Command457_Click()
    
    On Error GoTo Command13_Click_Err
    Me.ProstojeSubform.SetFocus
    
    DoCmd.RunCommand acCmdSelectAllRecords
    DoCmd.RunCommand acCmdCopy
    Dim xlapp As Excel.Application
    Set xlapp = CreateObject("Excel.Application")
    With xlapp
    .Workbooks.Add
    .ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:= _
    False
    .Cells.Select
    .Cells.EntireColumn.AutoFit
    .Visible = True
    .Range("a1").Select
    
    End With
    
    Command13_Click_Exit:
    Exit Sub
    Command13_Click_Err:
    MsgBox Error$
    Resume Command13_Click_Exit
    
 End Sub

I can export the form itself using OutputTo or the built in export but not sure how to combine them into one excel file.

Can populate cells of worksheet by direct reference .Range("A1").Value = Me.textboxname .

Then need to paste the subform data to a lower row. Select cell before pasting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM