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:

Forum statistics

Threads
1,081,702
Messages
5,360,738
Members
400,594
Latest member
Frothingslosh

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top