Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2006
    Posts
    1

    Run-time Error 3011 after 13093 times DoCmd.OpenReport

    Hi to everyone,

    I have a crazy error, running Access 2003 (Jet 4.0) on Windows XP. on a module, I open 13092 times a Report (with command OpenReport). At 13093rd time, Application goes on error 3011 "The Microsoft Jet Database engine could not find the Object ''. Make sure...".
    Here the "crazy" code:

    Public Function start() As Integer
    Dim count As Long
    Dim report As Variant
    report = "prova" ' this is a simple report with only one fix text
    Do
    count = count + 1
    If count > 20000 Then
    Exit Do
    End If
    Open "C:\log.txt" For Append As #78 ' this i a log file
    Print #78, count, report


    Close #78
    Application.DoCmd.OpenReport report, acNormal
    Loop
    End Function

    can someone tell me why this happens ??
    thanks and ciao
    ANDY

  2. #2
    Eugene-LS's Avatar
    Eugene-LS is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2018
    Location
    Murmansk
    Posts
    17
    Try this please
    Code:
    Public Function StartReport01() As Integer
    '
    '--------------------------------------------------------------------------
    Dim iCount As Integer, iCountEnd As Integer
    Dim sNoFormat As String
    Dim sReportName As String
    Dim sReportText As String
    Dim sReportPath As String
    
    On Error GoTo StartReport_Err
        iCountEnd = 20000 ' = Total reports
        sNoFormat = "00000"
        
        'sReportName = "prova" ' this is a simple report with only one fix text
        sReportName = "rptTest"
        
        'sReportPath = "C:\log.txt"
        sReportPath = "D:\Temp\Temp001.txt"
    
          
        If Dir(sReportPath, vbNormal) <> "" Then Kill sReportPath 'If file already present
        
        Open sReportPath For Append As #1 ' this is a log file
        
        For iCount = 1 To iCountEnd
            Application.DoCmd.OpenReport sReportName, acNormal
            Print #1, Format(iCount, sNoFormat); " - "; sReportName
        Next iCount
    
        MsgBox "Done!", vbInformation, "Printing Report " & sReportName
    
    StartReport_End:
        On Error Resume Next
        Close #1
        Exit Function
    
    StartReport_Err:
        MsgBox "Error: " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
        "in Function: StartReport in module: 00ModuleForTests", vbCritical, "Error in Application"
        Err.Clear
        Resume StartReport_End
    End Function
    or ...
    Code:
    Public Function StartReport02()
    'IMHO Faster way
    '--------------------------------------------------------------------------
    Dim iCount As Integer, iCountEnd As Integer
    Dim sNoFormat As String
    Dim sReportName As String
    Dim sReportText As String
    Dim sReportPath As String
    Dim iMet100%, x%, iMetAll%   'for PG all as Integer
    Dim sFilter$ 'as String
    On Error GoTo StartReport_Err
        iCountEnd = 3000 '0 '= Total reports
        sNoFormat = "00000"
        
        'sReportName = "prova" ' this is a simple report with only one fix text
        sReportName = "rptTest"
        
        'sReportPath = "C:\log.txt"
        sReportPath = "D:\Temp\Temp001.txt"
    
    'Info in status bar:
        If iCountEnd > 100 Then iMet100 = iCountEnd \ 100 Else iMet100 = 1
        SysCmd acSysCmdClearStatus 'clear status bar
        SysCmd acSysCmdInitMeter, "Printing Report " & sReportName & " ...", 100 '
           
        If Dir(sReportPath, vbNormal) <> "" Then Kill sReportPath 'If file already present
        
        DoCmd.OpenReport sReportName, acViewPreview ', , acHidden
    
        
            
        Open sReportPath For Append As #1 ' this is a log file
        
        For iCount = 1 To iCountEnd
           
            sFilter = "RecID = " & iCount 'Filter by RecodID  for example
            '
            Reports(sReportName).Filter = sFilter
            Reports(sReportName).FilterOn = True
            'Debug.Print "Filter: " & sFilter, vbInformation, "Printing Report " & sReportName
            DoCmd.PrintOut , , , acMedium, 1 'Print One copy by new filter
            
            Print #1, Format(iCount, sNoFormat); " - "; sReportName 'record to TXT file
            
            'Info in status bar:
            x = iCount \ iMet100
            If x > iMetAll Then
                iMetAll = x
                'Debug.Print iMetAll & "%"
                SysCmd acSysCmdUpdateMeter, iMetAll 'Show progress in status bar
            End If
        Next iCount
        
        Reports(sReportName).Filter = ""
        Reports(sReportName).FilterOn = False
        DoCmd.Close acReport, sReportName 'Close report
        MsgBox "Done!", vbInformation, "Printing Report " & sReportName
    'Info in status bar:
        SysCmd acSysCmdClearStatus 'clear status bar
    
    StartReport_End:
        On Error Resume Next
        Close #1
        Exit Function
    
    StartReport_Err:
        MsgBox "Error: " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
        "in Function: StartReport in module: 00ModuleForTests", vbCritical, "Error in Application"
        Err.Clear
        Resume StartReport_End
    End Function

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I must be missing something. You want to open a report and send it to the printer 20,000 times??
    Or are you just lucky that you're not mapped/connected to a printer?

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I agree with Micron. This code is very strange.


    Looking at your code, this is how I would structure it:
    Code:
    Public Function start() As Integer       '<--- "Start" is a reserved word
        Dim count As Long       '<---------------- "Count" is a reserved word
        Dim report As String       '<------------ "Report" is a reserved word
        Dim FileNumber       '<--- added
    
        report = "prova"    ' this is a simple report with only one fix text
        count = 1
    
        Do While count < 20000       '<--- Changed
    
            FileNumber = FreeFile    '<--- Gets first unused file number
    
            Open "C:\log.txt" For Append As #FileNumber    ' this is a log file
            Print #FileNumber, count; Tab; report
            Close #FileNumber
    
            DoCmd.OpenReport report, acNormal
            count = count + 1
        Loop
    End Function
    Don't know why you are using a function.

    Maybe change "start" to "StartUp"
    Maybe change "count" to "LoopCount"
    Maybe change "report" to "MyReport".

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    Suspect the OP is not around - the original post was 13 years ago and did not get a response until now - must be close to a record

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Plus the OP never posted again.
    Quite amazed Eugene managed to find such an obscure post for his first contribution.
    Welcome to our new colleague in Murmansk
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #7
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I guess it was my turn to fall into that trap.
    In my own defense, I was following, not leading!

  8. #8
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    uuuuuh.....
    I've gotta start focusing....

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 0
    Last Post: 11-06-2008, 12:29 PM
  2. Run time error '6': Overflow
    By wasim_sono in forum Access
    Replies: 0
    Last Post: 06-22-2007, 06:44 AM
  3. DoCmd.SendObject Help
    By bgreer5050 in forum Programming
    Replies: 0
    Last Post: 01-12-2007, 06:27 PM
  4. Run Time Error 424
    By ddog171 in forum Programming
    Replies: 3
    Last Post: 02-04-2006, 07:13 AM
  5. Replies: 1
    Last Post: 12-09-2005, 09:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums