Results 1 to 9 of 9
  1. #1
    Rosier75 is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    18

    Hiding Command Buttons in Reports?

    Hello all. Here's my latest question. Is there a way make visible/hide a command button on an Access report based on the value of another field on the report?



    Essentially, if Text1 is null, Command2.Visible = No. If Text1 is not null, Command2.visible = Yes

    I've seen articles on the internet that address this with Forms but can't find a solution for reports.

    Thanks

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Code in Format event is where to place this kind of code. However, Format event executes only for PrintPreview or direct to printer. Buttons cannot be clicked in PrintPreview anyway. You might just be out of luck. Reports are not intended to be 'action' objects.
    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
    Rosier75 is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    18
    Thanks for the info.

  4. #4
    A S MANN is offline Advanced System Analyst
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    India
    Posts
    164
    On load event of Report
    Use VBA

    if IsNull([Text1]) Then
    Me.Command2.Visible = False
    Else
    Me.Command2.Visible = True
    End If
    Try this

  5. #5
    Rosier75 is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    18
    Thanks for the input. That didn't do the trick. Will probably have to rethink my approach on this.

    Thanks again

  6. #6
    A S MANN is offline Advanced System Analyst
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    India
    Posts
    164
    Can you explain what was the problem. I am using above approach in many of my form and report and they works fine. Can you share a copy of Database with problematic report to identify the source of error.
    Thanks

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    I did some testing and can't get code to work for report. The button shows in ReportView and does not show in PrintPreview regardless of the code.

    Why even need button on report?
    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.

  8. #8
    roaftech is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Nov 2012
    Location
    Romania
    Posts
    65
    I stand to be corrected, but IIRC the report doesn't open until the end of the Report_Open sub and therefore the fields in your report don't actually exist at the time when you are trying to make the comparison.

    I spent several hours trying to get some code like yours to work before I remembered having seen the sequence explained somewhere. In my case, I was trying to hide the '#Error' in the report footer totals if the data was outside the specified period, by comparing the latest valid date in the data with the date specified in the filter. What I wanted was a "After_Open" event but there isn't one for reports.

    I did resolve it, but only by comparing appropriate fields on the forms from which the report is generated. ('Me' is the report)
    Code:
        If Forms!LatestRecord.Date < Forms!DateSelector.FirstDate Then
            Me.TotalItems.Visible = False
        Else
            Me.TotalItems.Visible = True
       End If
    The first form is used only for this comparison, but you do have to remember to open it (visible=False) before the main report will recognise it.
    The second form builds a filter before opening the report.
    In your case, you need to check the data that 'Text1' reads from.

    BTW, I do think that June7's last question is a valid one. Might be better to set up a parameter form

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    roaftech, code behind report can use data from the report RecordSource. I do this to set visibility of some controls. Example from Detail section Format event:
    Code:
        If IsNull(![207.Method]) Then
            .linFracture.Visible = True
        End If
        If IsNull(![605.method]) Then
            .linMoisture.Visible = True
        End If
    These reports open to a single record.

    I couldn't get anything to manage the command button.
    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. Showing/Hiding Navigation Buttons in VBA or Macro
    By chris.williams in forum Forms
    Replies: 3
    Last Post: 11-15-2011, 10:38 AM
  2. Command Buttons - Hiding/Unhiding
    By Hello World in forum Forms
    Replies: 4
    Last Post: 10-10-2011, 07:51 AM
  3. Shortcut or Command Buttons On Reports
    By stu_C in forum Reports
    Replies: 1
    Last Post: 08-23-2011, 11:57 AM
  4. Command Buttons
    By BLD21 in forum Access
    Replies: 2
    Last Post: 05-10-2011, 06:27 AM
  5. Command Buttons
    By Rosier75 in forum Access
    Replies: 3
    Last Post: 03-09-2011, 11:59 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