creating a report for an access pivot table

N

noorhanabbas

Hello,
Could anyone advise me on how to create an access report for a pivot table
that was created using access.

I tried using subreports but I could not export the pivot table to neither
word nor excel...

Thank you very much.

Nora
 
S

Stefan Hoffmann

hi Nora,

Could anyone advise me on how to create an access report for a pivot table
that was created using access.
I tried using subreports but I could not export the pivot table to neither
word nor excel...
Do you want an Access report or an Excel export of it?

The Excel export is quite easy:

Public Sub Export()

On Local Error Resume Next

Dim ea As Object
Dim es As Object
Dim ew As Object

Dim rsData As DAO.Recordset
Dim rsField As DAO.Field

Dim DisplayAlerts As Boolean
Dim SQL As String

Set ea = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Set ea = CreateObject("Excel.Application")
ea.Visible = False
End If

On Local Error GoTo LocalError

DisplayAlerts = ea.DisplayAlerts
ea.DisplayAlerts = False

Set ew = ea.Workbooks.Add
ew.Sheets.Item(3).Delete
ew.Sheets.Item(2).Delete
Set es = ew.Sheets.Item(1)
es.Name = "Pivot"

SQL = "SELECT * FROM yourPivotQuery"

Set rsData = CurrentDbC.OpenRecordset(SQL, dbOpenSnapshot)
If Not rsData.BOF And Not rsData.EOF Then
For Each rsField In rsData.fields
es.Range(Chr(65 + rsField.OrdinalPosition) & "1").FormulaR1C1 = _
rsField.Name
Next rsField
es.Range("A2").CopyFromRecordset rsData
End If
rsData.Close
Set rsData = Nothing

es.Columns.AutoFit
ea.DisplayAlerts = DisplayAlerts
ea.Visible = True

Set es = Nothing
Set ew = Nothing
Set ea = Nothing

Exit Sub

LocalError:
MsgBox Err.Description

End Sub


mfG
--> stefan <--
 
N

noorhanabbas

Hi Stefan,
Thank you very much for your prompt reply....
Does that mean that I must write VB code to be able to export an Access pivot
table report to either Excel or Word?

I thought I could use the Office Link to button instead?!

Thanks,

Nora.
 
S

Stefan Hoffmann

hi Nora,

Thank you very much for your prompt reply....
Does that mean that I must write VB code to be able to export an Access pivot
table report to either Excel or Word?
I thought I could use the Office Link to button instead?!
You can use it. Open the pivot view and click on the button. The
question is:
If you need an Excel export, I would recommend the export using the code
posted. It gives you more control over the Excel output as you may apply
any kind of formatting to it.



mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top