Can a command button on an Access 2007 form be conditionally displayed?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • David Anderson
    New Member
    • Jul 2010
    • 2

    #1

    Can a command button on an Access 2007 form be conditionally displayed?

    I recently began working with Access 2007, but I do have a limited experience with prior versions.

    I have a form with a button whose visibility I would like to make conditional on the Month value of Now(). I would like the test to be done any time the form is displayed. I have been unable to find any macros or VBA code examples showing me how to accomplish this, so I'm beginning to wonder if it can be done. In simple pseudo code, here's what I'd like to do:

    Code:
    If(Month(Now())=1,Button.Visible=True, If(Month(Now())=12,Button.Visible=True,Button.Visible=False))
    Is something like this possible to do in Access 2007?

    Thanks for looking.

    Dave Anderson
    Bismarck ND
    Last edited by NeoPa; Jul 27 '10, 10:38 AM. Reason: Please use the [CODE] tags provided
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #2
    Certainly David.

    Include this code as your form's Open event procedure :
    Code:
    Private Sub Form_Open()
        Me.Button.Visible = ((Month(Date) = 1) Or (Month(Date) = 12))
    End Sub

    Comment

    • David Anderson
      New Member
      • Jul 2010
      • 2

      #3
      Conditional Command Button Visibility

      Something so simple? Thank you for the response-I will try this first thing tomorrow.

      Comment

      Working...