Avatar of bill201
bill201
 asked on

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
Microsoft AccessProgrammingDatabases

Avatar of undefined
Last Comment
bill201

8/22/2022 - Mon
pdebaets

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

bill201

ASKER
I've already get from you this code, now i need a code to move the mouse cursor
pdebaets

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.
Your help has saved me hundreds of hours of internet surfing.
fblack61
IrogSinta

@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
bill201

ASKER
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.
SOLUTION
IrogSinta

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
bill201

ASKER
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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
bill201

ASKER
Maybe it's related to the problem: my  windows system measurement are in centimeters
IrogSinta

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
SOLUTION
pdebaets

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
IrogSinta

I have to agree with Peter here.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
bill201

ASKER
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
ASKER CERTIFIED SOLUTION
Jeffrey Coachman

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
bill201

ASKER
Well you convinced me to give it up. Thank you for the detailed explanation
Jeffrey Coachman

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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
bill201

ASKER
thanks alot for your comment is educated and teach and important   much more than just a simple technical answer