Solved

move the mouse on access 2013 form with vba

Posted on 2013-05-23
16
1,717 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
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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 167 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 166 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 167 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

825 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