help with the hittest method

GU_mr_Sand_Man

Board Regular
Joined
May 26, 2004
Messages
88
Hello. I am trying to get a small dialog box to pop up when an entry in a listbox is highlighted with the mouse. I believe I need to use the hittest method to make this work. Here's my code thus far:

Code:
Private Sub lstDistrict_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim Item As Object
    Set Item = lstDistrict.HitTest(X, Y)
    If Not (Item Is Nothing) Then
        Me.Caption = Item.Text
    Else
        Me.Caption = ""
    End If
End Sub

When I run this, I get a compile error, "Method or data member not found". How can I resolve this? Also, for my purposes, is the above code correct? Any help would be greatly appreciated.
 
Hi Jeremy

I have seen similar solutions for doing this on the internet (using VB6) but am having some trouble adapting them for VBA. However, I started to think there must be a simple solution to this.

You mentioned earlier that you are using a list box and you also mentioned that you do not have enough room on your form. I would think the list box itself takes up a large amount of space on your form. Have you considered using a combo box instead? This takes up a lot less space and if you did then you wouldn't need to use a 'MouseMove' event to update the 'ToolTipText' property. Are you also aware that you can show mulitple columns within the combo box itself? Again, that doesn't require space on the form itself, the additional information would automatically appears next to the number when you select the drop down arrow. I believe this would have the desired effect with a lot less trouble and complication.

HTH, Andrew
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Thanks for the idea Andrew; unfortunately this project has been complete for the past two weeks. I truly appreciate the feedback.

J
 
Upvote 0

Forum statistics

Threads
1,226,240
Messages
6,189,822
Members
453,572
Latest member
mrjohn500

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top