Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

move the mouse on access 2013 form with vba

Posted on 2013-05-23
16
Medium Priority
?
1,855 Views
Last Modified: 2013-05-24
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
Comment
Question by:bill201
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 3
  • +1
16 Comments
 
LVL 12

Expert Comment

by:pdebaets
ID: 39192863
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
 

Author Comment

by:bill201
ID: 39192868
I've already get from you this code, now i need a code to move the mouse cursor
0
 
LVL 12

Expert Comment

by:pdebaets
ID: 39192903
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
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 29

Expert Comment

by:IrogSinta
ID: 39192916
@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
 

Author Comment

by:bill201
ID: 39192957
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
 
LVL 29

Assisted Solution

by:IrogSinta
IrogSinta earned 668 total points
ID: 39192976
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
 

Author Comment

by:bill201
ID: 39192985
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
 

Author Comment

by:bill201
ID: 39192996
Maybe it's related to the problem: my  windows system measurement are in centimeters
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 39193010
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
 
LVL 12

Assisted Solution

by:pdebaets
pdebaets earned 664 total points
ID: 39193040
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
 
LVL 29

Expert Comment

by:IrogSinta
ID: 39193048
I have to agree with Peter here.
0
 

Author Comment

by:bill201
ID: 39193056
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
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 668 total points
ID: 39193145
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
 

Author Comment

by:bill201
ID: 39193647
Well you convinced me to give it up. Thank you for the detailed explanation
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39194733
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
 

Author Comment

by:bill201
ID: 39194862
thanks alot for your comment is educated and teach and important   much more than just a simple technical answer
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we’ll look at how to deploy ProxySQL.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
Progress
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question