Error printing reports in a collection. (1 Viewer)

rudeboymcc

Registered User.
Local time
Yesterday, 16:24
Joined
Sep 9, 2008
Messages
69
Hi. I currently open my reports using collections so i can have multiple instances.
Code:
Option Compare Database
Option Explicit
'Author:    Allen J Browne, July 2004
Public clnDS As New Collection
Function OpenADSReport()
    'Purpose:   Open an independent instance of form    
Dim rpt As Report
   On Error GoTo OpenAReport_Error
    'Exit Function
    'Open a new instance, show it, and set a caption.
            Set rpt = New Report_rptDS
            Set rpt = New Report_rptDS
            rpt.Caption = [Forms]![DS]![Expr1]
            clnDS.Add Item:=rpt, Key:=CStr(rpt.Hwnd)
 
    rpt.Visible = True
 
    Set rpt = Nothing
   On Error GoTo 0
   Exit Function
OpenAReport_Error:
    Call ErrorLog(Err.Description, Err.Number, "mdlOpenAReport")
End Function

This works perfectly. The problem is when I try and print using file>print, (with teh print dialogue) I get the error:
"this action can't be carried out while processing a form or report event"
and then it proceeds to print just fine.

To find the problem, I deleted ALL the vba code behind my report, and I still get the error. The above code is the only thing that runs.

Wierd thing is, if I add a print button on the report, with only docmd.printout behind it, it works fine every time.

The other wierd part is if I use this button, then printing from file>print also works fine.

What could be causing this error? If I knew whre the code was I'd just put a "resume next" whenever it turns up but there is no code behind the report.
 

Trevor G

Registered User.
Local time
Today, 00:24
Joined
Oct 1, 2009
Messages
2,341
Can I ask what you are trying to achieve? Is it that you want to print the report multiple times? If so you could set up a text box on your form and place in a number then get the print option to print via a loop based on the number in your textbox.

Like this:

Private Sub cmdPrintAll_Click()
Dim intPrint As Integer

Do Until intPrint = Me.txtboxNameNoOfTimes
DoCmd.OpenReport "ReportName", acViewNormal, , "ID= " & Me.ID
intPrint = intPrint + 1
Loop
End Sub
 

rudeboymcc

Registered User.
Local time
Yesterday, 16:24
Joined
Sep 9, 2008
Messages
69
sorry didn't make myself clear. All I'm trying to do is print one copy of the report. and this works but with an annoying error.

The button on the report with docmd.printout works fine but i want the file>print to work as well.
 

Trevor G

Registered User.
Local time
Today, 00:24
Joined
Oct 1, 2009
Messages
2,341
Can you upload a sample of the database with the report in it and the form. Remove any information you feel is sensitive.
 

rudeboymcc

Registered User.
Local time
Yesterday, 16:24
Joined
Sep 9, 2008
Messages
69
In an effort to strip everything out to upload to here, i've found what i think is causing the problem.

I had a group with a sum on one field. As soon as I deleted this the print function worked fine.

If I go back to a previous version adn copy that textbox in (with only "=sum([Amount])" as it's control source), then I can recreate the error.

Once I delete it and recreate it using access's group/sort feature, the new one does not have the problem.

Wierd, must be just a damaged textbox. Is this heard of before?
 

Users who are viewing this thread

Top Bottom