How do I show a picture on mouse over control button (1 Viewer)

Hydra427

Registered User.
Local time
Today, 06:38
Joined
Mar 9, 2012
Messages
40
Good Morning, I have a control button showing text and I would like to display a picture when I hover over that control button and disappear when I move on to the next control button. As an example I have 3 control buttons with the text "Apple", "Pear" and "Orange". When I hover over the text "Apple", I would like a picture of an Apple to be displayed next to it but as soon as I move to the "Pear" text a picture of a Pear appears next to it. Can anyone help me out on this.

I found this but am having trouble where to put the code to make it work correctly.

Add below code to form on which you have added all the label, button and image.

Option Compare Database

Private Sub Command0_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Image1.Visible = True Then Exit Sub
Image1.Visible = True
End Sub

Private Sub Form_Load()
Image1.Visible = False
End Sub
Private Sub Label4_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Image1.Visible = False
End Sub


Thanks, John
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:38
Joined
Oct 29, 2018
Messages
21,358
Hi John. It might be easier if you could post a sample db, so we can show you how to apply that code into your form.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 10:38
Joined
Feb 19, 2013
Messages
16,553
not sure where you got that code, but it is only intended to point you in the right direction.

Recommend as a start, include Option Explicit just below Option Compare Database and then click on debug>compile
 

Hydra427

Registered User.
Local time
Today, 06:38
Joined
Mar 9, 2012
Messages
40
Hi John. It might be easier if you could post a sample db, so we can show you how to apply that code into your form.
It is still a work in progress but what I am looking for is when I hover over the Name (Command Button) it displays a picture of the model associated with that name. When I move off that name it closes that picture and opens another one when I hover over that name, etc. I use this form to open the main screen in which I can get a better view of that model as you can see in the last screen shot.
1636036894879.png
1636037131012.png
1636037226832.png
1636037505414.png
 

CJ_London

Super Moderator
Staff member
Local time
Today, 10:38
Joined
Feb 19, 2013
Messages
16,553
are these buttons, textboxes or labels? and how is the form constructed? continuous? single with zillions of controls? subforms?
 

Hydra427

Registered User.
Local time
Today, 06:38
Joined
Mar 9, 2012
Messages
40
are these buttons, textboxes or labels? and how is the form constructed? continuous? single with zillions of controls? subforms?
The main form is the Yellow form from which I select the model. Each Name on the form is a Command Button that opens the Blue form with the model associated with that name.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 10:38
Joined
Feb 19, 2013
Messages
16,553
so what happens when you add a new model?

Have to say this seems to be a very labour intensive way of displaying all your models for a search. Are you aware there is a maximum lifetime limit of 754 controls on a form. If you already have 20 controls and then create a new control and then delete it, that is 21 controls towards your limit. Appreciate you appear to have only used around 150 of them so far.

The code you have provided almost certainly is not appropriate - you have 240+ controls so far, adding another 240 image controls and 240 labels will take you to 720 controls and almost certainly make the form very slow to populate.

As DBG says - better to upload a copy of your db, otherwise please answer these questions
What have your tried so far?
How do you (propose to) identify which image to show? is it based on the button caption? the tag? the button name? something else?
Where are the labels referred to in the code? To use the code as supplier probably needs another 240 controls taking you up to 720+.
What is the naming convention for your buttons, image controls and labels?
Will you consider a more efficient way of doing this?

@isladogs has some code to display information using a listbox rather than numerous buttons. By including his name he should become aware of this post and may b able to contribute
 

Hydra427

Registered User.
Local time
Today, 06:38
Joined
Mar 9, 2012
Messages
40
so what happens when you add a new model?

Have to say this seems to be a very labour intensive way of displaying all your models for a search. Are you aware there is a maximum lifetime limit of 754 controls on a form. If you already have 20 controls and then create a new control and then delete it, that is 21 controls towards your limit. Appreciate you appear to have only used around 150 of them so far.

The code you have provided almost certainly is not appropriate - you have 240+ controls so far, adding another 240 image controls and 240 labels will take you to 720 controls and almost certainly make the form very slow to populate.

As DBG says - better to upload a copy of your db, otherwise please answer these questions
What have your tried so far?
How do you (propose to) identify which image to show? is it based on the button caption? the tag? the button name? something else?
Where are the labels referred to in the code? To use the code as supplier probably needs another 240 controls taking you up to 720+.
What is the naming convention for your buttons, image controls and labels?
Will you consider a more efficient way of doing this?

@isladogs has some code to display information using a listbox rather than numerous buttons. By including his name he should become aware of this post and may b able to contribute
I am willing to do anything. The code that I posted was just something I found on the internet. I am looking for the most efficient way and easiest way to do this.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:38
Joined
Oct 29, 2018
Messages
21,358
I am willing to do anything. The code that I posted was just something I found on the internet. I am looking for the most efficient way and easiest way to do this.
Hi. What you are asking to do is very easy but hard to explain. That's why I said it would be easier to show you. For example, I don't see anything wrong with the code you found, and it's probably the same one I would use. So, I could post a similar code here, but I am not sure if that would be any helpful than if you posted a demo db, so we can show you where to put that code. Are you not able to do that?
 

Hydra427

Registered User.
Local time
Today, 06:38
Joined
Mar 9, 2012
Messages
40
Hi. What you are asking to do is very easy but hard to explain. That's why I said it would be easier to show you. For example, I don't see anything wrong with the code you found, and it's probably the same one I would use. So, I could post a similar code here, but I am not sure if that would be any helpful than if you posted a demo db, so we can show you where to put that code. Are you not able to do that?
I guess I am just not sure what you mean by a sample data base. Here I just created a simple form and when I hover my mouse over the command button I want to display a picture next to it of that object. When I move my mouse off the command button I want the picture to disappear.
 

Attachments

  • Sample DB.accdb
    448 KB · Views: 424

CJ_London

Super Moderator
Staff member
Local time
Today, 10:38
Joined
Feb 19, 2013
Messages
16,553
by sample, something with realistic data. We have no idea how you are storing your pictures, which picture you want (post #6 shows 6 pictures for one model), how you identify them.

Your sample does not even have the example code you provided which has the sentence 'Add below code to form on which you have added all the label, button and image.' which implies you got this from a web page somewhere.

We get what you want to do, what we don't get is what we actually have to work with
 

theDBguy

I’m here to help
Staff member
Local time
Today, 03:38
Joined
Oct 29, 2018
Messages
21,358
I guess I am just not sure what you mean by a sample data base. Here I just created a simple form and when I hover my mouse over the command button I want to display a picture next to it of that object. When I move my mouse off the command button I want the picture to disappear.
Yes, that's fine. We just need a way to "show" you how to use the code you found, since it's hard to explain it by simply describing what to do. Take a look at the attached and see how you might use the code to do what you want. Hope that helps...

PS. As @CJ_London said, since you gave us a generic sample, I can only give you a generic solution, which I hope you'll be able to understand and adapt to your actual situation. Cheers!
 

Attachments

  • Sample DB.zip
    21.6 KB · Views: 384

Hydra427

Registered User.
Local time
Today, 06:38
Joined
Mar 9, 2012
Messages
40
Yes, that's fine. We just need a way to "show" you how to use the code you found, since it's hard to explain it by simply describing what to do. Take a look at the attached and see how you might use the code to do what you want. Hope that helps...

PS. As @CJ_London said, since you gave us a generic sample, I can only give you a generic solution, which I hope you'll be able to understand and adapt to your actual situation. Cheers

Exactly what I am looking for, a quick question though. In your example of the event procedure you use Me.lblApple.Visible = True, I have got this to work for my sample DB using images. Can you explain a little bit about the "Me" in front of the statement and what it accomplishes?
 

isladogs

MVP / VIP
Local time
Today, 10:38
Joined
Jan 14, 2017
Messages
18,186
In your table, store the path to the image files then set the image control(s) to each of those in turn.

Attached is a short MP4 video of a form where I do something similar. Its low resolution to reduce file size
 

Attachments

  • ImagesOnMouseOver.zip
    1.6 MB · Views: 430
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 03:38
Joined
Oct 29, 2018
Messages
21,358
Exactly what I am looking for, a quick question though. In your example of the event procedure you use Me.lblApple.Visible = True, I have got this to work for my sample DB using images. Can you explain a little bit about the "Me" in front of the statement and what it accomplishes?
"Me" is the shorthand to refer to the current object. In this case, your form where the code is running. I'm sure others can elaborate further. I am not sure what else to add at this time. If I find a link to explain it, I'll post it here. Cheers!
 

isladogs

MVP / VIP
Local time
Today, 10:38
Joined
Jan 14, 2017
Messages
18,186
Ah! I downloaded your very simple db but have only just read the first few posts in this thread and looked at your form screenshot..

First of all I agree that your form layout is problematic in many ways. Lots of controls, very closely spaced with very small font size and not much space between items. It will be difficult for mouse move code like that in my video example (similar code to that in post #1) to work reliably
You also have the major issue of hitting the official form limit of 754 controls. In practice its about 950 in more recent versions of Access

You are welcome to look at the listbox mouse move examples that are on my website: Move Forms & Controls - Mendip Data Systems
There are 6 example forms. Forms 4 & 5 are the ones to look at.
Do have a look in case it helps, but I doubt you can use that type of code in your form. Sorry!
 

CJ_London

Super Moderator
Staff member
Local time
Today, 10:38
Joined
Feb 19, 2013
Messages
16,553
Colin, my thinking was 6 listboxes listing 40 records in each listbox and 1 image control which is visible next to the hovered over list item and populated with something -path/filename? -as part of the mousemove event. So 7 controls rather than 720. It may be you are saying the list rows are too short for your code to work effectively?
 

isladogs

MVP / VIP
Local time
Today, 10:38
Joined
Jan 14, 2017
Messages
18,186
It might work as long as each listbox displayed all the items in that column without scrolling.
Scrolling the listbox isn't supported with my mouse move code
Listboxes will automatically increase the vertical spacing for legibility. That means fewer items per listbox ...and hence more than 6 listboxes

However, I still think the form structure will be a nightmare to administer and, at some point. extra items will cause it to crash
 

CJ_London

Super Moderator
Staff member
Local time
Today, 10:38
Joined
Feb 19, 2013
Messages
16,553
don't disagree
@Hydra427 - you have been provided with suggestions as to how you might do it based on the limited information you have provided and been advised by everyone that it won't be easy, difficult to maintain and is not scalable. If you want more help you need to provide us with your database structure and an explanation of why you want the form that way -what benefit does it provide? We can see it attempts to list everything on one screen, but what would be wrong with a scrolling form for example (such as you find on shopping web sites)
 

Users who are viewing this thread

Top Bottom