• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1897
  • Last Modified:

move the mouse on access 2013 form with vba

hi

how can i can with vba to set the mouse cursor to a specific value on a specific record in a access form

for a example i want that the mouse course will be  on a record Where the the  id=1 and the mouse cursor will be  on the (column) field name CustomerName
0
bill201
Asked:
bill201
  • 7
  • 4
  • 3
  • +1
3 Solutions
 
pdebaetsCommented:
With Forms!MyFormName
    .recordsetclone.findfirst "ID = 1"
    if .recordsetclone.nomatch then
        msgbox "Record not found."
    else
        .bookmark = .recordsetclone.bookmark
        CustomerName.setfocus
    endif
End With

Open in new window

0
 
bill201Author Commented:
I've already get from you this code, now i need a code to move the mouse cursor
0
 
pdebaetsCommented:
Try this (includes a small but critical modification):

With Forms!MyFormName
    .recordsetclone.findfirst "ID = 1"
    if .recordsetclone.nomatch then
        msgbox "Record not found."
    else
        .bookmark = .recordsetclone.bookmark
        !CustomerName.setfocus
    endif
End With

Open in new window


this assumes that the control is named "CustomerName".

Let me know if it doesn't work, or if some error appears. If an error appears, please post the exact text of the error message.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
IrogSintaCommented:
@Peter, I believe he wants to have the mouse cursor hover right over the matching record and not just the record to have the focus.

@bill201, May I ask what the purpose is to have the mouse over this selected field?  Placing a mouse at a specific position may be possible but it is not as simple as one would think.  If the records are in a continuous form or listbox with a scrollbar, it would be quite difficult to calculate the position on the screen if the scrollbar is not at the top of the list.

Ron
0
 
bill201Author Commented:
pdebaets:
Thank you for your reply but as IrogSinta wrote it was not what I mean.

IrogSinta:

Thank you for explaining what I mean.

I want to do this for reasons of visual and beauty, but if it's complicated is not worth working on it. But I think that it should not be so complicated, I want to just move from the current mouse location down several inches vertically, I can play it until I find the exact measurement please just tell me how to move the mouse vertically with vba.
0
 
IrogSintaCommented:
If you add this code to the top of a module:
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
you can then set the mouse position with this statement:
SetCursorPos 200, 100
The first number is the x position and the second number is the y position.
0
 
bill201Author Commented:
thanks for your answer but i have a compile error

i put this code on a module:
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
SetCursorPos 200, 100
End Function

Open in new window


but i get a compile error on the SetCursorPos 200, and this message content is
compile error:
Invalid outside procedure
0
 
bill201Author Commented:
Maybe it's related to the problem: my  windows system measurement are in centimeters
0
 
IrogSintaCommented:
SetCursorPosition should be within the procedure where you are finding your record.

As I mentioned, this line should be at the top of a module and not inside a procedure.
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
0
 
pdebaetsCommented:
On a side note, I think you'll find that the users will not like having their mouse cursor moved around the screen for them.
0
 
IrogSintaCommented:
I have to agree with Peter here.
0
 
bill201Author Commented:
Depending on personal preferences, it is a record that I move down a line (in a continues form) and I want the mouse will still be marked on the record so I can continue to download line without moving the mouse
0
 
Jeffrey CoachmanCommented:
bill201,
<But I think that it should not be so complicated, >
Obviously you are wrong about that...
;-)
Your new requirement complicates this more

<I move down a line>
Move down the line how?
...Using the arrow keys or using the vertical scroll bar?


Lets be clear, you want to actually 'move' the mouse cursor to a field?
Why not just move the "focus" to the control (on the current event of the form), this is *Much* easier to do.
But here, ...even this may not be perfect because a user may choose to click in another field.
Private Sub Form_Current()
    If Not Me.NewRecord Then
        Me.CustomerName.SetFocus
    End If
End Sub


< want to do this for reasons of visual and beauty, >
?
Can I ask the need for this nonstandard interface?
Things like this are a nightmare to manage because of issues like:
window size, application size, differing user screen resolutions, ...etc

There is no other application that I know of that does what you are asking for here.
Thus the difficulty you are having getting a solid solution.

Many new developer like to "dream up" cool interfaces.
But all too many times, these types of nonstandard interfaces are more trouble than they are worth.
The issues and glitches you may encounter (trying to allow for every user action) may cancel out any benefits of "beauty".

JeffCoachman
0
 
bill201Author Commented:
Well you convinced me to give it up. Thank you for the detailed explanation
0
 
Jeffrey CoachmanCommented:
To be even clearer...
;-)

My post was not meant to discourage you.
Nor was it meant to prevent other experts from trying to help you out.

It's just that, again, I have never seen an interface like you were requesting in MS Access (or any other platform)

So you can see that even the top experts here were struggling to get you what you wanted...

You can certainly take the info presented here and research different techniques for positioning the mouse.
But as another expert mentioned, having the mouse appear in positions that the user did not move it to, may befuddle users.

Questions like this are sometimes better dealt with if you first start with the problem, then ask for advice in solving it.
This way Experts can provide a variety of solutions.
As opposed to you telling us the way you would like to do it.
By you telling us, ...you force us to perhaps circumvent normal interface design practices.

This all being said, ...there will always be exceptions to the rule, and sometimes a custom interface is needed.
;-)

Enjoy the weekend

JeffCoachman
0
 
bill201Author Commented:
thanks alot for your comment is educated and teach and important   much more than just a simple technical answer
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now