Problem showing preview of report. (1 Viewer)

Royce

Access Developer
Local time
Today, 13:23
Joined
Nov 8, 2012
Messages
99
I use the following code in many place to open and print a log. I would like to let the User preview the report, then decide if they want to print the log, which seems easy, but the Preview view that shows always show a blank "LogText" control.

Code:
If bolErrorsFound Then
        strReport = "rptProcessingLog"
        DoCmd.OpenReport strReport, acViewPreview, , , acHidden
    
        Report_rptProcessingLog.Title = "MyTitle : " & strCustom
       
       ' LogText is a public property of the report
        Report_rptProcessingLog.LogText = strLog
        
        DoCmd.SelectObject acReport, strReport
        DoCmd.PrintOut acPrintAll
    
    End If
Is there a way to make the report show the changed text?
 

vbaInet

AWF VIP
Local time
Today, 19:23
Joined
Jan 22, 2010
Messages
26,374
I don't follow, because in your code the report itself is set to open hidden. So could you be looking at the wrong report?
 

Royce

Access Developer
Local time
Today, 13:23
Joined
Nov 8, 2012
Messages
99
  • It is opened "Hidden".
  • then we set the value of the Title and an unbound text control.
  • then we select the report object, which makes the report visible, but the unbound control is shown empty, as it does not get repainted when we the value is set after it is opened.
  • Then the report is printed. (Which uses the new value, as it reformats everything for the printer.)
The only "fix" I know of is to write the log to a temp table and rework the report to use the temp table. That is easy to do, but I don't want to have to go back and change all the places the processing log report is called. I'm hoping someone knows an easier way.
 

vbaInet

AWF VIP
Local time
Today, 19:23
Joined
Jan 22, 2010
Messages
26,374
Ah, I forgot that SelectObject also makes a hidden object visible.

Try it this way:
Code:
    If bolErrorsFound Then
        strReport = "rptProcessingLog"
        DoCmd.OpenReport strReport, acViewPreview
        
        Report_rptProcessingLog.Title = "MyTitle : " & strCustom
       
       ' LogText is a public property of the report
        Report_rptProcessingLog.LogText = strLog
        
        DoCmd.PrintOut acPrintAll
    End If
Are you sure that those variables have values? Step through the code and check the Locals window.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 19:23
Joined
Feb 19, 2013
Messages
16,635
why not pass the two values through using the openargs and in the report open evet, split the openarg and assign to the two controls

DoCmd.OpenReport strReport, acViewPreview, , , ,strCustom & "|" & strLog

and in the report open event

Code:
 dim hdrs() as string
 hdrs=split(me.openargs,"|")
 Title = "MyTitle : " & hdrs(0)       
LogText = hdrs(1)
)
 

Royce

Access Developer
Local time
Today, 13:23
Joined
Nov 8, 2012
Messages
99
Kicking myself, don't know why I didn't try that. Old code gave me blinders I guess.
Did have to handle the OpenArgs in the Load Event instead of Open.

What's nice is I added the code and none of the other calls had to change.
 

vbaInet

AWF VIP
Local time
Today, 19:23
Joined
Jan 22, 2010
Messages
26,374
I tend not to use OpenArgs if I'm passing more than one value, or if I need to handle Nulls and preserve its type (which doesn't apply in your case). I much prefer using either global variables, a Type or a Class.

Set the global variable/type/class variables before opening the report and call the variable/type/class in the report's Open/Load event.
 

Users who are viewing this thread

Top Bottom