Adding watermark to a Access report page

不羁岁月 提交于 2021-02-11 18:09:12

问题


I am trying to add a watermark to an Access report using the "Picture" property and have run into an issue. The following code works and the image is displayed/printed when the report is previewed and printed but does not work when the report is directly printed from a macro (nothing visible on-screen). "GrandTotal" is a bound text box on the report that is the sum of a field in the record source. I would appreciate any suggestion to print the watermark from both the print preview and the print macro.

Private Sub Report_Load
' put up the watermark if needed

    If GrandTotal.Value < 2000 Then
        Me.Picture = <<picture file name including full path>>
    End If
End Sub

回答1:


Since you are printing the report without it ever rendering to the screen the open/load events are never fired because they are never used. An alternative could be to open the report in print preview and use the OpenArgs to indicate you want to print it

Private Sub SomeButton_Click()
    DoCmd.OpenReport "DetailView", acViewPreview, , , acHidden, "Print"
End Sub

then do your normal loading stuff

Private Sub Report_Load
' put up the watermark if needed

    If GrandTotal.Value < 2000 Then
        Me.Picture = <<picture file name including full path>>
    End If
End Sub

and when the loading is done your form will Activate which is when you can print

Private Sub Report_Activate()
    If Me.OpenArgs = "Print" Then
        On Error GoTo ErrorHandler

        DoCmd.OpenReport "Report1", acViewPreview
        'Opens print dialog for current screen (report in this case):
        DoCmd.RunCommand acCmdPrint
    End If
    DoCmd.Close
ErrorHandler:
    If Err.Number <> 0 And Err.Number <> 2501 Then
        MsgBox "Error: " & Err.Number & vbNewLine & Err.Description
        Exit Sub
    End If
End Sub

The form is never shown so it looks like you had it set up before but the load/open events will fire like normal because the report is actually rendered.



来源:https://stackoverflow.com/questions/29853386/adding-watermark-to-a-access-report-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!