Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

Command Button Color Change on Mouse Button-down Action

Introduction.

After working with the Command Button and Message Box Controls of MS-Access I really got bored with their styles. So, I set out to do something about it and created some animation styles for the command buttons and used Office Assistant (valid only for Access2003 and earlier versions) for Message Boxes. The Links of those Articles and free downloads links are given below:

    Command Button Styles

  1. Command Button Animation
  2. Command Button Animation-2
  3. Colorful Command Button

    Message Box Styles (Access2003 or earlier versions only)

  4. Message Box with Office Assistant
  5. MsgBox with Options Menu
  6. MsgBox with Checkbox Menu

Some New Trick on Command Button.

Here is some new trick for you to use on Command Button Control. Command Button will change color on the mouse-button down action and will restore original color on the mouse-up action.  You can do this with a Label control, with the same dimension of the Command Button, filled with the color you like and by placing it behind the Command Button Control.  You need two lines of VBA Code on the Form Module as well.


Design the New Animation Style.

Let us go through with this simple design and enjoy the new animation style of the Command Button Control.

  1. Open a new Form.
  2. Create a Command Button Control on the Detail Section of the Form.
  3. Display the Command Button’s Property Sheet (F4).
  4. Change the Name Property Value to cmdClose.
  5. Change the Caption Property Value to Close.
  6. Create a Label Control with some caption text near the Command Button.
  7. Select the Command Button and the Label Control together.
  8. Right-click on it and highlight Size option on the Shortcut Menu and select To Tallest.
  9. Repeat step-8 above and select To Widest.
  10. Click on the Label Control alone and display it’s Property Sheet (F4).
  11. Remove the text from the Caption property.
  12. Change the Special Effect Property value to Raised.
  13. Select the Back Color Property and click on the Build ( . . .) button to display the Color Palette.
  14. Select the color you like to fill the background of the label control.
  15. Move the Label control behind the Command Button control and place it completely hidden.
  16. If the label control is overlapping the Command Button then display the Shortcut Menu by right-clicking on it and select Send to Back from the Position group.
  17. Click on the Command Button and display the property sheet (F4).
  18. Click on the Event Tab and select the Mouse down Event, select [Event Procedure] from the drop-down control and click on the build (. . .) button to open the Form’s VBA Module Window.
  19. Copy and Paste the following Code into the Form Module, over-writing the existing two empty lines appeared there:
    Private Sub cmdClose_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
      Me.cmdClose.BackStyle = 0 'transparent
    End Sub
  20. Repeat step-18 for Mouse Up [Event Procedure] and copy and paste the following Code into the Form Module:
    Private Sub cmdClose_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) 
        Me.cmdClose.BackStyle = 1 'Normal 
    End Sub

Test Run.

Now, it is time for the test run of our design. 

  1. Save the Form with the name frmButton.
  2. Open frmButton in Form View.
  3. Click on the Command Button and hold the mouse button down.  You will see the Command Button’s Color changes to the background fill color you have selected for the label control and Command Button caption text Close appearing on it.
  4. Release the mouse button.  The original state of the Command Button is restored.

The trick works by changing the Back Style of the Command button to transparent, forcing it to display the color of the Label control behind and changes to Normal view, when the mouse button is released. 

You can learn another trick from an earlier Article on Transparent Command Button, from here.


  1. Command Button Animation
  2. Double Action Command Button
  3. Colorfull Command Buttons
  4. Transparent Command Button
  5. Command Button Animation-2
  6. Creating Animated Command Button with VBA
  7. Command Button Color Change on Mouse Move

Share:

Translate



PageRank
Subscribe in a reader
Your email address:

Delivered by FeedBurner

http://clicky.com/101199826
Blog Directory Visit blogadda.com to discover Indian blogs

Search

Popular Posts

Search This Blog

Blog Archive

Powered by Blogger.

Follow by Email

Labels

Forms Functions How Tos MS-Access Security Reports Class Module msaccess forms Animations msaccess animation Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Array External Links Queries msaccess reports msaccess tips Accesstips Downloads Objects Property Collection Object Event Menus and Toolbars Controls MsaccessLinks Process Controls WithEvents Art Work msaccess How Tos Combo Boxes Graph Charts List Boxes VBA msaccessQuery Command Buttons Dictionary Object Form Report Calculation Command Button Data Emails and Alerts Query RaiseEvent Custom Functions Custom Wizards DOS Commands Data Type Object Reference ms-access functions msaccess functions msaccess graphs msaccess reporttricks Item msaccessprocess security advanced Access Security Add Auto-Number Field Type Fields Form Instances Key Macros Menus SubForm Top Values Variables msaccess email msaccess menus progressmeter Access2007 Copy Excel Expression Join Methods Microsoft Numbering System Records Recordset Security Split Table Time Difference Utility Workgroup Wrapper Classes database function ms-access msaccess wizards reference text tutorial vba code Access2003 Accounting Year Action Animation Attachment Binary Numbers Bookmarks Budgeting ChDir Color Palette Conditional Formatting Data Filtering Defining Pages Diagram Disk Dynamic Lookup Error Handler Export External Filter Formatting Groups Hexadecimal Numbers Import Labels List Logo Macro Mail Merge Main Form Memo Monitoring Octal Numbers Operating System Paste Primary-Key Product Rank Reading Remove Rich Text Sequence SetFocus Summary Tab-Page Tables Union Query User Users Water-Mark Word automatically commands hyperlinks iSeries Date iif msaccess msaccess alerts pdf files restore switch toolbar updating upload

Featured Post

Opening Access Objects from Desktop

Frequently Used Methods. Set the Form Name in Display Form Option of Current Database in Access Options . BIG DEAL!, this is the first t...

Labels

Blog Archive

Recent Posts