this action cannot be carried out while processing a form or report event (1 Viewer)

dzirkelb

Registered User.
Local time
Today, 15:47
Joined
Jan 14, 2005
Messages
180
I'm trying to have a page automatically print every 10 seconds when there are results. The 10 second timer is good, the report and print is good, but when I try to print it via VB, it gives the error "this action cannot be carried out while processing a form or report event" and highlights the DoCmd.PrintOut line

Code:
Private Sub Form_Timer()
    DoCmd.SetWarnings False
    Dim db As DAO.Database
    Dim rs As Recordset
    Dim ssql As String
    Set db = CurrentDb()
    
    ssql = "SELECT Mfg, CustName, PONumber, OrderNum, PartID, Inspect, ReceivedID, PrintLocation, PrintQty, Part FROM ReceivingPrintTemp"
    Set rs = db.OpenRecordset(ssql, dbOpenSnapshot, dbSeeChanges)
    
    Do While Not rs.EOF
        DoCmd.PrintOut , , , , 3
    rs.MoveNext
    Loop
    
    rs.Close
    Set rs = Nothing
    
    dbc.Close
    Set dbc = Nothing
    
    DoCmd.SetWarnings True
End Sub
 

Cronk

Registered User.
Local time
Tomorrow, 06:47
Joined
Jul 4, 2013
Messages
2,774
PrintOut is to print whatever active object is showing on the screen. There is one?

I never use PrintOut, preferring to have a report showing the required information.

Incidentally, what is the purpose of looping through the recordset because if PrintOut did work, you'd get 3 copies for every record in the recordset?
 

dzirkelb

Registered User.
Local time
Today, 15:47
Joined
Jan 14, 2005
Messages
180
I do want 3 copies of every record in the recordset (actually, that 3 will be changed to the PrintQty field from the query results, this is just testing).

how do I automatically print a report then if I don't use printout? What is it that I need to use?
 

Cronk

Registered User.
Local time
Tomorrow, 06:47
Joined
Jul 4, 2013
Messages
2,774
Lookup
docmd.openreport "yourReportName"

Rather than printing out x reports, each with one record, I'd be having one report with all records, each on a separate page if needs be.

Also, recommended practice is ensure the recordset is at the beginning before entering the loop by putting

recordset.movefirst

on the line before
Do while not rst.eof
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:47
Joined
May 7, 2009
Messages
19,249
use docmd.openreport "reportname". do this 3 times and it will print your report 3 times. also you upon entering the timer event, you should first cancel it (Me.TimerInterval=0). then reinstate it again before exiting your timer event.
 

Users who are viewing this thread

Top Bottom