Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8248495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:12:30+00:00 2026-06-07T23:12:30+00:00

In an Access 2003 database, I have an employee status/feedback report that is generated

  • 0

In an Access 2003 database, I have an employee status/feedback report that is generated through VBA. I create the report in VBA because the desired formatting of report is such that I found it to be easier for me to do it this way (combining multiple recordsets, displaying more than one record from a recordset aligned with others, customizing some formatting elements based on department, etc.). There may be a better way to create these reports, but this is functioning just fine, so I’d rather avoid recreating if possible.

My problem is this: As this is an employee feedback form, there are details that supervisors want to be able to see, but not show the employee. When the report is generated, the supervisor has a chance to review the data/make changes from the report itself (via userforms, event handling on the report). Part of the review is to look at one set of fields (added to the report as labels), but these fields should be hidden when the report is ultimately printed.

In my head, I thought I had seen before a way to hide specific controls in this way and did some googling to find this MSDN resource on DisplayWhen. However, it appears that DisplayWhen is usable only on forms. Is there a way to set this value (or similar/related option) using reports? Doing a search on SO, I found only one single question in a query for DisplayWhen, which was not helpful to me.

Using .Visible = False on the creation of the report of the report won’t work because the supervisors will need to see those fields. It does not appear that I can set this property upon printing, as I see no event handling option for this. Can I create a custom event handler that will capture the print command?

Here’s the control creation code:

Private Sub AddOneOnOneField(Rpt As Report, Left As Integer, Top As Integer, Width As Integer, Height As Integer, _
    Optional Cap As String = vbNullString, Optional Align As Integer = cnFontCenter, Optional Size As Integer = 10, _
    Optional Bold As Integer = cnBoldFont, Optional DisplayWhen As Byte = 0)

    With CreateReportControl(Rpt.Name, acLabel, acDetail, vbNullString, vbNullString, _
        Left, Top, Width, Height)

        .Properties("FontSize") = Size
        .Properties("FontWeight") = Bold
        .Properties("BorderStyle") = 1
        .Properties("TextAlign") = Align
        .Properties("Caption") = Cap
        .Properties("DisplayWhen") = DisplayWhen ' This does not work!
    End With

End Sub

To reiterate my questions:

  • How can I set certain report fields to only display on print preview, but not on print?
  • Can I create a custom event handler that will capture the print command from a report?
  • Is there a way to set the DisplayWhen property (or similar/related option) on a report field?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:12:33+00:00Added an answer on June 7, 2026 at 11:12 pm

    This was not ideal, but it works. When creating the report through VBA, I already had code to create code within the report module. I added to that function to capture the print/force hiding of the fields, print, then un-hide.

    Private Sub AddReportCode(mdlNew As Module)
    Dim sNewCode As String
    
        sNewCode = "Option Compare Database" & vbCr & "Option Explicit"
        sNewCode = sNewCode & vbCr
        sNewCode = sNewCode & vbCr & "Public Sub CapturePrint()"
        sNewCode = sNewCode & vbCr & "Dim v As Variant"
        sNewCode = sNewCode & vbCr & "If Application.CurrentObjectName = ""OneOnOneReport"" And Application.CurrentObjectType = acReport Then"
        sNewCode = sNewCode & vbCr & "DoCmd.OpenReport ""OneOnOneReport"", acViewDesign"
        sNewCode = sNewCode & vbCr & "Reports(""OneOnOneReport"").Visible = False"
        sNewCode = sNewCode & vbCr & "For Each v In Reports(""OneOnOneReport"").Controls"
        sNewCode = sNewCode & vbCr & "If Left(v.Properties(""Name""), 3) = ""Occ"" Then"
        sNewCode = sNewCode & vbCr & "v.Visible = False"
        sNewCode = sNewCode & vbCr & "End If"
        sNewCode = sNewCode & vbCr & "Next v"
        sNewCode = sNewCode & vbCr & "DoCmd.OpenReport ""OneOnOneReport"", acNormal"
        sNewCode = sNewCode & vbCr & "DoCmd.OpenReport ""OneOnOneReport"", acViewDesign"
        sNewCode = sNewCode & vbCr & "For Each v In Reports(""OneOnOneReport"").Controls"
        sNewCode = sNewCode & vbCr & "If Left(v.Properties(""Name""), 4) = ""HIDE"" Then"
        sNewCode = sNewCode & vbCr & "v.Visible = True"
        sNewCode = sNewCode & vbCr & "End If"
        sNewCode = sNewCode & vbCr & "Next v"
        sNewCode = sNewCode & vbCr & "Reports(""OneOnOneReport"").Visible = True"
        sNewCode = sNewCode & vbCr & "DoCmd.OpenReport ""OneOnOneReport"", acViewPreview"
        sNewCode = sNewCode & vbCr & "End If"
        sNewCode = sNewCode & vbCr & "End Sub"
    
        mdlNew.DeleteLines 1, mdlNew.CountOfLines
    
        mdlNew.InsertText sNewCode
    
    End Sub
    

    For readability, here’s the actual code that is in the module after this runs:

    Option Compare Database
    Option Explicit
    
    Public Sub CapturePrint()
    Dim v As Variant
    If Application.CurrentObjectName = "OneOnOneReport" And Application.CurrentObjectType = acReport Then
        DoCmd.OpenReport "OneOnOneReport", acViewDesign
        Reports("OneOnOneReport").Visible = False
        For Each v In Reports("OneOnOneReport").Controls
            If Left(v.Properties("Name"), 3) = "Occ" Then
                v.Visible = False
            End If
        Next v
        DoCmd.OpenReport "OneOnOneReport", acNormal
        DoCmd.OpenReport "OneOnOneReport", acViewDesign
        For Each v In Reports("OneOnOneReport").Controls
            If Left(v.Properties("Name"), 4) = "HIDE" Then
                v.Visible = True
            End If
        Next v
        Reports("OneOnOneReport").Visible = True
        DoCmd.OpenReport "OneOnOneReport", acViewPreview
    End If
    End Sub
    

    When adding new controls to the report (see original code in question body), I added the ability to optionally assign a name to the control:

    .Properties("Name") = NewName
    

    The control creation code was called with a NewName argument of "HIDE" & ControlTop & ControlLeft to allow for naming all the needed controls without duplicating names. Before hiding, the report is opened in design mode to prevent screen flickering/slowdown. The printing code then cycles through all the controls on the report looking for names starting with “HIDE” and hides them. Once all controls are hidden, the report is reopened as normal to print, then the process repeats to unhide these controls and display the original report to the user.

    I still was not able to capture the print event properly (and this is where the solution becomes not my favorite option), so instead I prompted the user at the initial creation of the report to print, calling the newly created CapturePrint Sub (while hiding those fields). If they opt not to, then they can print as normal without hiding the fields, or regenerate the report to hide them/be prompted again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Access 2003 database that connects to a SQL Server 2008 box
So I have an access mdb file that was originally create using Access 2003/Office
I have an Ms-Access database (2003) and I have noticed that it gives OledbException:
I have an MS Access 2003 database that I'm using to develop a basic
I have a Access 2003 database that will dynamically load MDB databases as a
I have an Access 2003 database using MS-JET linked tables (that is, there are
I have an Access 2003 database that makes use of a combobox that contains
I have a database in Access 2003 that I only want certain people to
I have an Access database (in Access 2003) with several tables, and data must
I have Access 2003, and Crystal Reports 10 (the one that comes with VS2008

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.