Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return Object Name with VB? 2

Status
Not open for further replies.

Hanss

Technical User
Feb 15, 2001
85
CH
I have an access form with a number of rectangles (box1, box2 box3 etc.). I also have a field named "position". On the "On Mouse Move" of "section detail" I would like to have some code that enters the name of the object where the cursor is, into field "position". For example, when the cursor is over box1, box1 appears in field "position". When the cursor is over box2, box2 appears in field "postion".

Would appreciate any help!

Kind regards,
Hanss
Zurich, Switzerland
 
I forget which events have the X & Y coordinates,
of your cusor, msybe mouseMove(probably).

I believe each control, has a "Top" & "Left" property.

You will have to use some clever (and tedious) logic,
to determine whether your cursor's x & y position,
has entered a controls top & left position.

actually, you'll also need the controls height & width prop.,
to determine the square area of the control.

You may find a unique identifier, by adding the properties
together for comparison.

eg; if x + y = ctl.Top + ctl.Left Then
 
How are ya Hanss . . .

The only problem with this is when you move outside the areas in question, you need to blank out your [blue]Position[/blue] control (empty string).

Also note: the [blue]Back Style[/blue] property of the rectangles have to be set to [blue]normal[/blue]. If set to [blue]transparent[/blue] movement is only detected when you cross the line, not while your in boundaries of the control. So . . .

In the code module of the form, copy/paste the following routine:
Code:
[blue]Public Sub movUpdate(ctlName As String)
   
   If Trim(Me!Position & "") <> ctlName Then
      Me!Position = ctlName
   End If
   
End Sub[/blue]
Next in the [blue]MouseMove[/blue] event of your controls of interest:
Code:
[blue]   Call movUpdate("[purple][b]ThisControlName[/b][/purple]")[/blue]
Finally, set the [blue]MouseMove[/blue] event of the form to:
Code:
[blue]   Call movUpdate("")[/blue]
[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Thank you both for your suggestions! I will try them and get back.

Hanss
 
Thank you so much for your help! You got me on the right track with the MouseMove event.

- Hanss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top