This tutorial is written as a how-to for a novice to master at creating, manipulating and coding MS Access databases. This tutorial assumes you have a general understanding of how to use the basic functions within MS Access, as well as how to view the underlying VBA code. I have included a sample database to allow you to see the code in action, and how it is utilized, as well as some other helpful resources that come in handy when using this method. The code is also included below for easy reference.
Please note that as with anything there is more than one way to do things and everyone attacks a problem from his or her angle or perspective.
I searched for a Mouse Over like effect for a project I worked on in 2001, and it was then that I realized that Microsoft failed to include some common functionality in the Access application. I found some solutions that partially did what I needed, but none were exactly what I was looking for. So I went to work and created a few test applications trying different things and identifying the bugs. The outcome provided a set of standard tools that I now use in many of my applications.
This is my guide to "Mouse Over Effects" within Microsoft Access.
The type of object to which you are applying Mouse Over Effects will determine which way is best. For instance, the effects are applied differently for a text box or label than they are for a shape, such as a square or a border. This tutorial covers the most straightforward implementation of my technique, but it can be changed to obtain more elaborate visual effects.
This section will cover applying a Mouse Over Effect to a text box, using a change in the font size, the font color, and font face.
Private Sub txtbxMouseOverTest_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) 'Create a Mouse Over Effect for the text box by increasing font size, changing font color, and font face Me.txtbxMouseOverTest.FontSize = 14 Me.txtbxMouseOverTest.ForeColor = vbRed Me.txtbxMouseOverTest.FontBold = True
Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) 'Set the default state for the controls that will have an onMouseOver effect applied Me.txtbxMouseOverTest.FontSize = 12 Me.txtbxMouseOverTest.ForeColor = vbBlack Me.txtbxMouseOverTest.FontBold = False 'If you want the label to change as well add its default state here Me.lblMouseOverTest.FontSize = 12 Me.lblMouseOverTest.ForeColor = vbBlack Me.lblMouseOverTest.FontBold = False End Sub
Remember: The control must be oversized enough to accommodate your choice of font size so it may be necessary to tweak this if you are going to increase the font size drastically.
End Tutorial for Mouse Over Effects on text box and label.
This Section covers how to apply some of the same thinking to a shape on your form.
Important: The shape must have a normal background. If you set it to transparent the Mouse Move event will only be effective when your mouse is over the line that creates the border of the shape. By filling in the shape the effect will work anytime you mouse is over any part of the shape.
Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) 'Set default state for rectangle Me.bxMouseOverTest.BorderColor = vbBlack Me.bxMouseOverTest.BorderWidth = 3 End Sub
Private Sub bxMouseOverTest_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) 'Create a Mouse Over Effect for the rectangle, changing its border color to red Me.bxMouseOverTest.BorderColor = vbRed End Sub
End Tutorial for Mouse Over effects on shapes.
In some cases, the Mouse Over effect may appear to flicker or flutter, if this occurs you more than likely have some sort of a form repaint or requery action occurring. If that is the case you may have to throw some IF statement onto the form detail section to ensure that your text box or label is in the desired default state prior to the mouse moving over them see code example below.
'This will give the label a on mouse over effect - return to original font size If Me.lblYOUR LABEL.FontSize = 10 Then Me.lblYOUR LABEL.FontSize = 9 If Me.lblYOUR LABEL1.FontSize = 10 Then Me.lblYOUR LABEL1.FontSize = 9 If Me.lblYOUR LABEL2.FontSize = 10 Then Me.lblYOUR LABEL2.FontSize = 9
The example provided only covers changing control colors using built-in vb colors, limiting your color options. If you refer to the attached Excel document, you will find the conversion table for over 300 colors. It provides information to convert from HEX to RGB and MS Access. The code has to change slightly when using a different method of choosing colors. For instance, if you were to use an MS Access color code the syntax would be as follows.
Me.lblYOUR LABEL NAME= 221695
This example is an orange color.
This concludes my tutorial on how to force MS Access to emulate a Mouse Over Effect programmatically. I hope you found it helpful. If you have any questions or comments please feel free to me me here on EE.
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.