[AccessD] changing report caption via code for display in print que

John Bartow john at winhaven.net
Fri Apr 16 10:59:43 CDT 2010


A.D.,
Thank you so much! 

Exactly what I was looking for. Modified it to fit my situation and
everything works great!

John B.

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of A.D. Tejpal
Sent: Thursday, April 15, 2010 7:37 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] changing report caption via code for display in print
que

John,

    It is observed that if a report is printed directly by opening in normal
view, the caption assigned programmatically in report's open event does not
get properly captured in the print queue documents of the printer.

    This is explained by the fact that caption of active window tends to get
captured for the above purpose. Depending upon the local set up, direct
opening of report might not project its window presence adequately. For
absolute certainty, it is therefore necessary that the report is first
opened in preview mode, followed by PrintOut and Close actions. 

    It would be interesting to note that you can't get away by opting the
preview in hidden mode. In that case, you might even end up with the caption
of your calling form getting depicted in print queue. The defining
requirement is that the report should be the visible active window (even if
for a very brief duration) when requisite information is getting passed to
the printer.

    Sample code in calling form's module, as placed below, should get the
job done. Time delay (in clock cycles) as included at various stages, as a
measure of abundant precaution, is meant for stabilization between one step
and the next.

Best wishes,
A.D. Tejpal
------------

' Sample code in calling form's module
'=========================
Private Sub CmdReport_Click()

    ' << Suitable code for setting up object
    ' variable (rst) to a single field recordset
    ' having names of reports to be printed>>

    With rst        
        .MoveFirst
        Do Until .EOF
            DoCmd.OpenReport .Fields(0), _
                                    acViewPreview
            P_Wait 200
            DoCmd.PrintOut
            P_Wait 100
            DoCmd.Close acReport, .Fields(0)
            P_Wait 100
                
            MoveNext
        Loop
            
        .Close
        Set rst = Nothing           
    End With
End Sub
'---------------------------------------------------

Private Sub P_Wait(WtCycles As Long)
    Dim Cnt As Long
    
    For Cnt = 1 To WtCycles
        DoEvents
    Next
End Sub
'==================================

  ----- Original Message ----- 
  From: John Bartow 
  To: _DBA-Access 
  Sent: Thursday, April 15, 2010 07:25
  Subject: [AccessD] changing report caption via code for display in print
que


  I'm working on making niceties for an application which generates about
  30,000 sheets to be printed by a Imagerunner 110 device. This device uses
a
  Linux controller box to que/hold/start the jobs. Since there are so many
  jobs it would be nice to be able to distinguish them while in the que. So
  I'm attempting to have the account number of each client show up in the
  caption of the report when printed in order to have the account number
show
  in the print que of the printer. Depending on the report it should appear
  something like: Order Form - 029384
   
  In my procedural code I use this type of command to print various reports:
  DoCmd.OpenReport "rptOrderForm", acViewNormal
   
  I placed this in the report's module expecting it to accomplish this task:
  Private Sub Report_Open(Cancel As Integer)
  Me.Caption = Me.Caption & " - " & CurrentAcct()
  End Sub
   
  The report will display the caption as I intended if opened in a preview
  window and then it will display it in the print que once printed but it
will
  not display it if opened with acViewNormal which sends it directly to the
  printer.
   
  Anyone have an idea of how I can achieve the intended results?
   
  Tia,
  John B.
-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list