Results 1 to 7 of 7
  1. #1
    Girraffa is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    32

    Question Make report text controls invisible based on another field value

    Hello esteemed colleagues!
    I have been struggling for awhile now with making some controls invisible in my report based on another control's value. The report isn't a "rows and totals" sort of report; instead the detail section is a set of fields from a table of largely text-type data from qualitative reports on animals for an animal care facility. This particular report is on incidents reported for particular animals. I have a field that indicates if the incident is "closed" (combobox) and subsequent fields for: the date it was closed, comments on the closure, a checkbox for whether or not the records for the incident have been sent to the owner and another text field for detailing which records were sent and to whom. I would like all the fields I listed after the combobox to be invisible when the incident is not closed. I have tried putting the following code in the "on format" event of the detail section to no avail:
    Code:
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If Me.cboClosed = -1 Then
    Me.txtDateClosed.Visible = True
    Me.txtClosedComnts.Visible = True
    Me.chkRecordsSent.Visible = True
    Me.txtRecordsTo.Visible = True
    Else
    Me.txtDateClosed.Visible = False
    Me.txtClosedComnts.Visible = False
    Me.chkRecordsSent.Visible = False
    Me.txtRecordsTo.Visible = False
    End If
    End Sub
    What am I doing wrong and/or is this possible?


    Thank you!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    put the code in the ON PRINT event:
    Code:
    sub OnPrint()
    dim bOn as boolean 
    bOn = Me.cboClosed = -1
    
    
    Me.txtDateClosed.Visible = bOn
    Me.txtClosedComnts.Visible = bOn
    Me.chkRecordsSent.Visible = bOn
    Me.txtRecordsTo.Visible = bOn
    end sub

  3. #3
    Girraffa is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    32
    ranman thank you for your quick response. I tried that but the controls still appear, both in print preview and in normal mode. I am wondering if my report setup is to blame?
    Query:
    Click image for larger version. 

Name:	ReportQueryDesign.JPG 
Views:	16 
Size:	106.8 KB 
ID:	32848
    top of report design:
    Click image for larger version. 

Name:	rptReport.JPG 
Views:	16 
Size:	137.3 KB 
ID:	32849
    bottom of report design with the fields in question:
    Click image for larger version. 

Name:	rptReportbottom.jpg 
Views:	16 
Size:	116.1 KB 
ID:	32850

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Combobox on a report really doesn't make sense. Change it to a textbox.

    Is IncidentClosed a yes/no type field? Why even have this field since you have a DateClosed field? If DateClosed is null then the incident is not closed. IncidentClosed field is redundant.

    Since you want the controls invisible when the incident is NOT closed, use NOT to reverse the Boolean returned.

    Me.txtDateClosed.Visible = Not IsNull(Me.DateClosed)

    But why bother with setting controls invisible? Will just leave a bunch of white space on the report where the controls sit.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    combo box is not needed on a report.

  6. #6
    Girraffa is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    32
    I was trying to make the reports appear cleaner because not all the fields are needed for all records, but I have checked with my boss and he says he is fine with blank fields. I agree about the combobox, that is a relic of a form being turned into a report and will fix that. That is also a good point about the incident closed/ date incident closed, thanks!
    I tried the code and couldn't make it work for me, I'm curious what I'm doing wrong but since it's not necessary I will have to backburner that. Thanks folks!

  7. #7
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    hmm, it should work. Put a breakpoint (f9) on bOn = Me.cboClosed = -1
    and see what the values are when it stops.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 10-30-2016, 07:09 AM
  2. Replies: 3
    Last Post: 08-07-2014, 08:48 AM
  3. How to make a field invisible in form view?
    By snowboarder234 in forum Forms
    Replies: 3
    Last Post: 10-25-2012, 12:43 PM
  4. Replies: 1
    Last Post: 10-05-2011, 04:36 PM
  5. Invisible field in a report
    By ybg1 in forum Access
    Replies: 5
    Last Post: 01-05-2011, 03:19 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums