Results 1 to 4 of 4
  1. #1
    tagteam is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    501

    Report On format not working with vba

    have a boolean field (checkbox) in my report detail section for a suspended car. I have this code in the on format section



    If Me.Suspended = False Then
    Me.CLeaseSuspensionStart.Visible = False
    Me.CLeaseSuspensionEnd.Visible = False
    Else
    Me.CLeaseSuspensionStart.Visible = True
    Me.CLeaseSuspensionEnd.Visible = True
    End If

    however, it still shows all the fields no matter. what. Does this kind of code work in a report?
    Thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Yes, it should, but only for PrintPreview or direct to printer, not ReportView.

    Could simplify with:

    Me.CLeaseSuspensionStart.Visible = Me!Suspended
    Me.CLeaseSuspensionEnd.Visible = Me!Suspended

    But the control will still occupy space on form and there will be blank area.

    Instead of VBA, could have expression in textbox ControlSource: =IIf(Suspended, CLeaseSuspensionStart, Null)

    Then display view won't matter.

    Or maybe apply filter so suspended records are not included.
    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
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    depends on the view you have opened for the report (should be report or print preview), but it should work assuming all the fields exist in the current record

    Not sure why you need a suspended boolean field - the fact CLeaseSuspensionStart is populated tells you that.

    you could try simpler code

    Me.CLeaseSuspensionStart.Visible = not isnull(Me.CLeaseSuspensionStart)
    Me.CLeaseSuspensionEnd.Visible=Me.CLeaseSuspensionStart.Visible

    Ah - June got there first

  4. #4
    tagteam is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    501
    Ok, I see. I do need it in Report view because the user pulls it up to review data.

    I found a solution that works better for me. Kind of what June said but I created a subquery and tied that to the main query so that only cars that are actually suspended have a suspension record. Then when I run the report I can use the shrink method and have it hide the line when not suspended and show when it was suspended.

    So if anyone is views this thread later the answer for me was not to do it in the formatting but to do it in the query and then use shrink on the detail section and those individual field boxes.

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

Similar Threads

  1. Replies: 7
    Last Post: 11-16-2020, 12:03 PM
  2. Format For Minutes:Seconds - Sum Not Working
    By Desstro in forum Programming
    Replies: 4
    Last Post: 04-23-2018, 06:19 PM
  3. Format Function Not Working
    By gameemaster in forum Queries
    Replies: 3
    Last Post: 05-13-2017, 02:28 PM
  4. Replies: 3
    Last Post: 01-29-2013, 04:34 AM
  5. Excel number format not working in Access
    By toad848 in forum Access
    Replies: 3
    Last Post: 03-24-2009, 11:06 AM

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