Mouse over effect

oxicottin

Learning by pecking away....
Local time
Today, 00:19
Joined
Jun 26, 2007
Messages
888
Hello, I have two images (img1 and img2) and I want to have img1 visible when the form opens and when I run the mouse over img1 it changes it to visible = False and img2 is visible = True. Also when I mouse off the image it changes back to img1… How is this done? Thanks!
 
Microsoft Access form controls do not have a MouseOver event, but they do have a MouseMove event. Try pasting the following code into your form's code module (NOTE: make certain that the two images overlap EXACTLY):
Code:
Private Sub Form_Open( _
    Cancel As Integer)

    Me.img1.Visible = True
    Me.img2.Visible = False

End Sub

Private Sub Detail_MouseMove( _
    Button As Integer, _
    Shift As Integer, _
    X As Single, _
    Y As Single)

    Me.img1.Visible = True
    Me.img2.Visible = False

End Sub

Private Sub img1_MouseMove( _
    Button As Integer, _
    Shift As Integer, _
    X As Single, _
    Y As Single)

    Me.img1.Visible = False
    Me.img2.Visible = True

End Sub

See if this solution works for you.
 
Thanks You!!!
 
Just wanted to say ByteMyzer's treatment of this subject is great. Others mostly didn't spell it out. Wanted to add this quick note however...

I just quickly tried it on my form and it worked first time out...in a shorter form. I laid the primary link image directly over an exact copy created in a different color. Rather than swap both visible properties, I only needed to swap the visible property for the primary (top) image. The other shows automatically when the top image is invisible. (Both images have the same Hyperlink Address property setting.)

Thanks a million for your sub example. This works every bit as good as an HTML or CSS version on a web site! :)

Private Sub Form_Open(Cancel As Integer)

On Error GoTo Err_Form_Open
Me.imgQEWR_blue.Visible = True
Exit_Form_Open:
Exit Sub
Err_Form_Open:
MsgBox Err.Description
Resume Exit_Form_Open

End Sub

Private Sub Detail_MouseMove( _
Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
Me.imgQEWR_blue.Visible = True
End Sub
Private Sub imgQEWR_blue_MouseMove( _
Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
Me.imgQEWR_blue.Visible = False
End Sub
 
Addendum to my previous post with shorter example code:

I found that leaving the entire detail background of the form with continuous action to take was causing certain images on the form and the Properties window to flicker intermittently. My work-around for now is wrapping the actions code in "Private Sub Detail_MouseMove(etc)" with a conditional statement re the X/Y location of the mouse arrow. That way, it only activates those lines when the mouse is near the block of links portion of the Detail background (i.e.-long enough to change the image back, instead of forever):

With 6 links rather than the 1 in the earlier test example, the Details sub looks like this now (plus some necessary additional code, added to support the change re getting the X/Y location of the mouse). Standard error stuff added also.

Private Sub Detail_MouseMove( _
Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)

On Error GoTo Err_Detail_MouseMove

Dim MouseLocation As POINTAPI

GetCursorPos MouseLocation

If (Not (Trim(MouseLocation.tLng_Xloc) < 615 Or Trim(MouseLocation.tLng_YLoc) < 223 Or Trim(MouseLocation.tLng_Xloc) > 761 Or Trim(MouseLocation.tLng_YLoc) > 490)) Then
Me.imgMIDI_blue.Visible = True
Me.imgPlaylist_blue.Visible = True
Me.imgAVPAV_blue.Visible = True
Me.imgFacilitators_blue.Visible = True
Me.imgCalifornia_blue.Visible = True
Me.imgQEWR_blue.Visible = True
End If

Exit_Detail_MouseMove:
Exit Sub
Err_Detail_MouseMove:
MsgBox Err.Description
Resume Exit_Detail_MouseMove

End Sub

Additional necessary code was adapted from code written by CajunCenturion (at tek-tips.com). The additional adaptation code is below:

In a functions module...

Note: Option Compare Database & Option Explicit at the top of the module also.

Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Public Type POINTAPI
tLng_Xloc As Long
tLng_YLoc As Long
End Type

Additional code back in my form module:

Note: A separate sub was included for each link image (like the one in the earlier post), with these working in conjunction with the Details sub.

Also by CajunCenturion, this is a temporary sub using the code in the functions module to make it easy to determine the X/Y location of the mouse (commented in my module now, for later use...very handy):

Private Sub Detail_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Dim MouseLocation As POINTAPI

GetCursorPos MouseLocation

MsgBox "Cursor at " & Trim(MouseLocation.tLng_Xloc) & ", " & Trim(MouseLocation.tLng_YLoc)

End Sub

Hope this helps a little. Now there's no flicker. Wasn't all that important, but why have it when I don't need to...thanks to the many fine programmers out there, helping guys like me who know very little about VBA, etc.
 
I found that leaving the entire detail background of the form with continuous action to take was causing certain images on the form and the Properties window to flicker intermittently.
No need to sophisticated code in order to avoid this. Just check the visibility before change it and change it only if needed:

If you need to make a img visible:
Code:
If YourImg.Visibil then Exit Sub ' the img is already visible 
YourImg.Visible = True
 
Addendum to my previous post with shorter example code:

I found that leaving the entire detail background of the form with continuous action to take was causing certain images on the form and the Properties window to flicker intermittently.

With 6 links rather than the 1 in the earlier test example, the Details sub looks like this now. Standard error stuff added also.

(Correction code revised on advice from Mihail, and now works very smoothly...thanks!)

Private Sub Detail_MouseMove( _
Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)

On Error GoTo Err_Detail_MouseMove

If (Me.imgMIDI_blue.Visible = False) Then Me.imgMIDI_blue.Visible = True
If (Me.imgPlaylist_blue.Visible = False) Then Me.imgPlaylist_blue.Visible = True
If (Me.imgAVPAV_blue.Visible = False) Then Me.imgAVPAV_blue.Visible = True
If (Me.imgFacilitators_blue.Visible = False) Then Me.imgFacilitators_blue.Visible = True
If (Me.imgCalifornia_blue.Visible = False) Then Me.imgCalifornia_blue.Visible = True
If (Me.imgQEWR_blue.Visible = False) Then Me.imgQEWR_blue.Visible = True

Exit_Detail_MouseMove:
Exit Sub
Err_Detail_MouseMove:
MsgBox Err.Description
Resume Exit_Detail_MouseMove

End Sub
 

Users who are viewing this thread

Back
Top Bottom