Populating Unbound Text Box using cursor X and Y Coordinates

CWellard

New member
Local time
Yesterday, 17:32
Joined
Feb 6, 2012
Messages
3
Hello all.

I'm trying to build a fancy interface for a database and fear that I may have waded out of my depth.

The idea is that when scrolling the mouse accross the screen, different pieces of information are called in separate subforms.

The X-Y coordinate of the cursor will trigger different things to happen and call different queries.

One method I'm trying to sort is to populate an unbound text box with a specific field of a recordset.

the table is "tbl_XYEquivalent" the field I would like to return is "Location" and the fields I would like to lookup or query are "X" and "Y" (corresponding to the actual X and Y cursor coordinates respectively)

I could do this using IF statements but this crude method will become tiresome when I start to add new data entries. The record set is already 200 entries strong and if I can avoid typing out the if statements for each of the individual coordinates that would be great.

Maybe a loop could be used.

so far, I have constructed VBA to return the X and Y coordinates of the cursor to two text boxes on the form. These update in real time as the mouse is moved around the screen.

I would now like the "Location" text box to update in real time returning the location that corresponds to the XY values.

better still, if the cursor moves within a range (say +or- 5 of the actual value) of a certain location, the location would be returned to the unbound text box.

I hope this make sense and that someone has an idea of how to help.

thanks in advance.

Chris.
 
Last edited:
I'm not sure if this code is relevant to your requirement, however, you may get some ideas from it.

This code was written by a colleague in a different group. On a given form,in a controls Mousemove event, you can display different text (you could do whatever you want here)
when you are within the controls borders and different text when the mouse is outside that control's borders.

Code:
 ' Code in form's module
  '==============================
  ' Declarations section
  Private gX As Single, gY As Single
  '---------------------------------------------

  Private Sub CmdTest_MouseMove( _
                      Button As Integer, _
                      Shift As Integer, _
                      X As Single, Y As Single)
      
      With Me.CmdTest
          Me.CmdTest.Caption = "Test (MM)"
          
          If gX <> 0 Then
              If (X > (0.9 * .Width) And X > gX) _
                          Or (X < (0.1 * .Width) And _
                          X < gX) Then
                  Me.CmdTest.Caption = "Test"
              End If
          End If
          
          If gY <> 0 Then
              If (Y > (0.9 * .Height) And Y > gY) _
                          Or (Y < (0.1 * .Height) And _
                          Y < gY) Then
                  Me.CmdTest.Caption = "Test"
              End If
          End If
      End With
      
      gX = X
      gY = Y
  End Sub
  '==============================

      Normal caption of command button named CmdTest is "Test". When mouse
  pointer is brought over it, the caption changes to "Test (MM)". As & when
  the mouse pointer moves away from the control, the caption reverts back to
  normal, i.e. "Test".

      Note:
      (a) MouseMove event fires in rapid-fire style. Values for X and Y
  returned by this event have a range from 0 upto the width and height (in
  twips) of the control in question.
      (b) The multiplying factors of 0.9 and 0.1 used in the sample code could
  perhaps be fine tuned further (say 0.95 and 0.05) so as to narrow down the
  twilight zone. However a coarser setting as adopted above, is found
  conducive to more consistent behavior. This is because a deliberately wild
  mouse sweep by the user can result in X or Y value getting truncated short
  of the potential maximum, even though the mouse pointer has moved out.
 
Last edited:
Also I'm pretty sure this returns the co-oords in "twips" not pixels or mickeys, just so you know.
 

Users who are viewing this thread

Back
Top Bottom