F
FriPi
Hi
I have the following issue. I have a subform where data from a query is
shown following the selection made on my main form.
The data shown on my subform has been rearranged to have a certain layout,
different from the one in the source query.
I would like to export the data shown in my subform to an excel file with
exactly the same layout as in access.
This is the code I use, but the problem is the exported excel file has the
layout of the source query.
Is there any way to export data from a subform with exactly the same
layout???
Dim oExcel As Excel.Application
Dim DB As DAO.Database
Dim RS As DAO.Recordset
Dim I As Long
On Error Resume Next
Err.Clear
Set oExcel = GetObject(, "Excel.Application ")
If Err.Number <> 0 Then Set oExcel = CreateObject("Excel.Application")
On Error GoTo 0
With oExcel
.Visible = True
.workbooks.Add
.ActiveSheet.Name = CStr("SheetName")
Set DB = CurrentDb
Set RS = DB.OpenRecordset("Query", dbOpenSnapshot)
For I = 0 To RS.Fields.Count - 1
.Cells(1, I + 1) = RS.Fields(I).Name
Next I
.Range("A2").Select
.Selection.CopyFromRecordset RS
I have the following issue. I have a subform where data from a query is
shown following the selection made on my main form.
The data shown on my subform has been rearranged to have a certain layout,
different from the one in the source query.
I would like to export the data shown in my subform to an excel file with
exactly the same layout as in access.
This is the code I use, but the problem is the exported excel file has the
layout of the source query.
Is there any way to export data from a subform with exactly the same
layout???
Dim oExcel As Excel.Application
Dim DB As DAO.Database
Dim RS As DAO.Recordset
Dim I As Long
On Error Resume Next
Err.Clear
Set oExcel = GetObject(, "Excel.Application ")
If Err.Number <> 0 Then Set oExcel = CreateObject("Excel.Application")
On Error GoTo 0
With oExcel
.Visible = True
.workbooks.Add
.ActiveSheet.Name = CStr("SheetName")
Set DB = CurrentDb
Set RS = DB.OpenRecordset("Query", dbOpenSnapshot)
For I = 0 To RS.Fields.Count - 1
.Cells(1, I + 1) = RS.Fields(I).Name
Next I
.Range("A2").Select
.Selection.CopyFromRecordset RS