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:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,224,820
Messages
6,181,157
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top