More Microsoft Access Button Tricks

We already showed Microsoft Access programmers to use images behind buttons in a previous post.  Here is another trick for button.

You can use an image or label for a button.  This technique gives you the ability to give a “pushed in” appearance to Microsoft Access buttons.

The following example shows two labels.  It is simpler than showing two images.  When you click the left hand button (which is actually a label) it appears sunken and the caption is changed to “On”.  It will look like the right hand image.

Microsoft Access button using a label

Using a label for a sunken or raised effect

As a Microsoft Access programmer, this is not complex.  I will not cover the code to make the button do what you want, but only the code to show how to change the appearance.

Private Sub lblButton_Click()

If Me.lblButton.Caption = “Off” Then    ‘ Turning it on
With Me!lblButton
.Caption = “On”                   ‘ Change the caption
.SpecialEffect = 2                ‘ Make it sunken
End With
With Me.lblButton                   ‘ Turning it off
.Caption = “Off”                  ‘ Change the caption
.SpecialEffect = 1                ‘ Make it raised
End With
End If

End Sub

You are using the label’s caption to decide what code to run.  If the caption is currently “Off” you are obviously trying to turn it on.  If it is not “Off” it must be on so you are turning it off.  The SpecialEffect is 1 for raised and 2 for sunken.

An Access programmer can add code into the “if” statement.  For example it may be to display a part of the form or hide it.  In the “On” part of the if statement you might add something like

Me.subDetails.Visible = True

In the  “Off” part you add

Me.subDetails.Visible = False

Screen design and appearance can make a lot of difference in the acceptance a programmer receives when a new application is presented.  Simple things like the way buttons appear and work can be the difference between acceptance and rejection.  If you are doing Microsoft Access programming, take the time to add the finishing touches.

Tags: , , , ,

Leave a Reply