Solved

move the mouse on access 2013 form with vba

Posted on 2013-05-23
16
1,666 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
  • 7
  • 4
  • 3
  • +1
16 Comments
 
LVL 12

Expert Comment

by:pdebaets
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 29

Expert Comment

by:IrogSinta
Comment Utility
@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
Comment Utility
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 167 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Maybe it's related to the problem: my  windows system measurement are in centimeters
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 29

Expert Comment

by:IrogSinta
Comment Utility
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 166 total points
Comment Utility
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
Comment Utility
I have to agree with Peter here.
0
 

Author Comment

by:bill201
Comment Utility
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 167 total points
Comment Utility
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
Comment Utility
Well you convinced me to give it up. Thank you for the detailed explanation
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
Comment Utility
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
Comment Utility
thanks alot for your comment is educated and teach and important   much more than just a simple technical answer
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Creating and Managing Databases with phpMyAdmin in cPanel.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now