Results 1 to 6 of 6
  1. #1
    PinkDuster's Avatar
    PinkDuster is offline Advanced Beginner
    Windows 7 64bit Access 2013 32bit
    Join Date
    Aug 2017
    Location
    Cleveland area
    Posts
    65

    Conditional Visibility of Two Fields in my Report based on Value in combobox Not Working

    I have a report that shows products purchased in date order with some grouping. I only want the Customer name and the Quantity purchased to be visible for a particular transaction type, Wholesale transactions. I used the following code on the OnFormat event in the Report:



    Code:
     Private Sub Report_Current()
    If TxnTypes = "3" Then
    Reports!rptPartsSold.CustName.Visible = True
    Reports!rptPartsSold.Quantity.Visible = True
    Else
    Reports!rptPartsSold.CustName.Visible = False
    Reports!rptPartsSold.Quantity.Visible = False
    End Sub
    however, I still end up with the same report output, where Customer name and Quantity purchased are still showing.

    Click image for larger version. 

Name:	FieldVisibilityReport.PNG 
Views:	12 
Size:	9.8 KB 
ID:	32283

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Code is in Current event, not Format.

    If TxnTypes is a number type, do not use quote marks.

    Simpler code:

    Me.CustName.Visible = Me!TxnTypes = 3
    Me.Quantity.Visible = Me!TxnTypes = 3


    Instead of VBA, could have expression in textbox:

    =IIf([TxnTypes] = "3", Null, [Customer])
    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.

  3. #3
    PinkDuster's Avatar
    PinkDuster is offline Advanced Beginner
    Windows 7 64bit Access 2013 32bit
    Join Date
    Aug 2017
    Location
    Cleveland area
    Posts
    65
    I tried the following (some are commented out), but now I get no visibility at all, not conditional visibility.

    Code:
    Private Sub Report_Load()
    'If TxnTypes = 3 Then
    'Reports!rptPartsSold.CustName.Visible = True
    'Reports!rptPartsSold.Quantity.Visible = True
    'Else
    'Reports!rptPartsSold.CustName.Visible = False
    'Reports!rptPartsSold.Quantity.Visible = False
    
    Me.CustName.Visible = Me!TxnTypes = "3"
    Me.Quantity.Visible = Me!TxnTypes = "3"
    
    'Me.CustName.Visible = Me!TxnTypes = "Wholesale"
    'Me.Quantity.Visible = Me!TxnTypes = "Wholesale"
    End Sub
    TxnTypes is from a separate table that is part of the query used to generate the report. I tried 3 with and without the quotes; it is the ID for the type called "Wholesale".
    Last edited by PinkDuster; 01-21-2018 at 08:12 AM. Reason: make additional explanation

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    As already stated, code is in wrong event. Has to be in Format event. Format event of the section the controls are in. I presume they are in Detail section.

    Private Sub Detail_Format()

    Format events trigger only in print preview or direct to printer, not report view.
    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
    PinkDuster's Avatar
    PinkDuster is offline Advanced Beginner
    Windows 7 64bit Access 2013 32bit
    Join Date
    Aug 2017
    Location
    Cleveland area
    Posts
    65

    Thumbs up

    Thank you very much June7! I had overlooked putting the code in the correct place...I used the wrong event in the Report, rather than the Format event in Detail, where the controls were. I didn't know about the Format event triggering in print preview, thank you. It worked!

    Click image for larger version. 

Name:	FieldVisibilityFixed.PNG 
Views:	8 
Size:	10.0 KB 
ID:	32302

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Alternative is an expression in textbox:

    =IIf([TxnTypes] = 3, Null, [Customer])
    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.

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

Similar Threads

  1. Replies: 3
    Last Post: 05-10-2017, 12:30 PM
  2. Replies: 8
    Last Post: 12-13-2016, 02:11 PM
  3. Nz null not working in report from a combobox
    By caniread in forum Reports
    Replies: 2
    Last Post: 02-12-2016, 10:48 PM
  4. Replies: 16
    Last Post: 03-03-2014, 10:46 AM
  5. Field visibility based on ComboBox selection
    By cactuspete13 in forum Forms
    Replies: 3
    Last Post: 01-30-2013, 03:37 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