Hi,
I have an Access 2010 database which has very suddenly become very slow when either exporting to excel or outputting reports. The two common places where this happens are below (this code hasn't been changed any time recently). Any thoughts would be much appreciated!
Example 1 - Printing labels to pdf:
Example 2 - Exporting to excel:
Any thoughts?
I have an Access 2010 database which has very suddenly become very slow when either exporting to excel or outputting reports. The two common places where this happens are below (this code hasn't been changed any time recently). Any thoughts would be much appreciated!
Example 1 - Printing labels to pdf:
Code:
DoCmd.OutputTo acOutputReport, gStrReportName, acFormatPDF, strPathAndFile
Example 2 - Exporting to excel:
Code:
Dim cnn1 As ADODB.Connection
Set cnn1 = CurrentProject.Connection
Dim rstExport As New ADODB.Recordset
rstExport.ActiveConnection = cnn1
Dim rstSQL As String
Dim FilterName As String
Dim appExcel As excel.Application
Dim bks As excel.Workbooks
Dim wkb As excel.Workbook
Dim wks As excel.Worksheet
Dim rng As excel.Range
Dim i As Integer
Dim iNumCols As Integer
'Create a new instance of Excel
Set appExcel = CreateObject("Excel.Application")
appExcel.Application.Visible = False
Set bks = appExcel.Workbooks
Set wkb = bks.Add
Set wks = wkb.Sheets(1)
rstSQL = gStrReportQuery
rstExport.Open rstSQL
wks.Range("A2").CopyFromRecordset rstExport
Set rng = wks.UsedRange
iNumCols = rstExport.Fields.Count
For i = 1 To iNumCols
wks.Cells(1, i).Value = rstExport.Fields(i - 1).Name
Next
With wks.Range("a1").Resize(1, iNumCols)
.Font.Bold = True
.EntireColumn.AutoFit
End With
With wks
.Cells.EntireColumn.AutoFit
.PageSetup.PrintTitleRows = "A1"
End With
'Add a border to all the cells with data
With wks.UsedRange.Borders
.LineStyle = 1
.Weight = xlThin
.ColorIndex = -4105
End With
'Open the worksheet
appExcel.Application.Visible = True
appExcel.Application.ScreenUpdating = True
Exit_Sub:
Set rng = Nothing
Set wks = Nothing
Set wkb = Nothing
Set bks = Nothing
Set appExcel = Nothing
Any thoughts?