7: out of memory

ivan624888

New Member
Joined
Oct 4, 2019
Messages
5
Hi When I click button to generate report there is the 7 out of memory error popup

Private Sub btn_Click()
On Error GoTo ErrCheck


Dim strPeriod As String
Dim intFY As Integer
Dim strFMth As String


Dim cnt As New ADODB.Connection
Dim rst As ADODB.Recordset

Dim xlApp As Object
Dim xlWb As Object
Dim xlWs As Object

Dim fldCount As Integer
Dim recCount As Long
Dim iCol As Integer

' Open connection to the database
cnt.Open CONNECT_STRING_ADO


Dim intFYear As Integer


'Prompt user for fyear:
DoCmd.OpenForm "frmFYearSelect", acNormal, , , acFormEdit, acDialog


If DLookup("status_ok", "tblTemp_FYearSelect") = True Then
intFYear = DLookup("FYear", "tblTemp_FYearSelect")
Else
GoTo ExitRoutine
End If




' Define the recordset:
Set rst = fnDisconnectedRS("SELECT * FROM udv_rpt_extract_depr_current_KERRY WHERE fyear = " & intFYear & " ORDER BY asset_number, cost_centre, gl_number")
' Copy field names to the first row of the worksheet

' Create an instance of Excel and add a workbook
Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Add
Set xlWs = xlWb.Worksheets("Sheet1")

fldCount = rst.Fields.Count
For iCol = 1 To fldCount
xlWs.Cells(1, iCol).Value = rst.Fields(iCol - 1).Name
Next

' Copy the recordset to the worksheet, starting in cell A2
xlWs.Cells(2, 1).CopyFromRecordset rst

' Display Excel and give user control of Excel's lifetime
xlApp.Visible = True
xlApp.UserControl = True

' Auto-fit the column widths and row heights
xlApp.Selection.CurrentRegion.Columns.AutoFit
xlApp.Selection.CurrentRegion.Rows.AutoFit




'=========================
rst.Close
cnt.Close

Set rst = Nothing
Set cnt = Nothing

' Release Excel references
Set xlWs = Nothing
Set xlWb = Nothing
Set xlApp = Nothing

ExitRoutine:
Exit Sub

ErrCheck:
MsgBox err.Number & "->" & err.description
Resume ExitRoutine
End Sub


EDIT:
Also posted in Access forum here: https://www.mrexcel.com/forum/microsoft-access/1111561-7-out-memory-codes-provided.html
 
Last edited by a moderator:

Some videos you may like

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,089,216
Messages
5,406,897
Members
403,111
Latest member
Donbozone

This Week's Hot Topics

Top