Results 1 to 15 of 15

Virtual mouse click of button

  1. #1
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    212

    Virtual mouse click of button

    Does anyone know of a way to perform a virtual mouse click of button?



    For example, instead of the user clicking a button with the mouse, the button is clicked based on some condition by simulating a mouse click.

    The concept is similar to how a user can click a close button on a form themselves or they can program the DoCmd.Close to do the same thing based on a condition.

    Thanks in advance.

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    1,360
    You can call a buttons click event in code by making it public if it's not on the current form.
    If that's what you are trying to achieve ?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    212
    I know a Call command followed by the button click event procedure may be used. However, that is not what I am trying to do because it will not work in my particular circumstance.

  4. #4
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    212
    The way I reordered things as a workaround was I set focus to the button and now I just need to figure out how to virtually click it.

    Perhaps after SetFocus to the button I somehow initiate some sort of activate command?

  5. #5
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    1,360
    Okay - so what are you trying to do?
    An more detailed explanation might steer us to the right / best solution...
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  6. #6
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    212
    I understand you but it is quite a simple question. I have things setup a particular way for a reason. While there is another way I can do it, it will require much more programming. What I described is the simplest solution for the play of the problem, if there is a virtual click feature for VBA.

  7. #7
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    212
    I will try something like this:

    Code:
    [Forms]![frmViewCase].[btnViewCaseClose].SetFocus [Forms]![frmViewCase].[btnViewCaseClose].Activate
    Perhaps this will help the community understand what I am getting at. The code prior to and after is irrelevant for situation.

  8. #8
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    212
    I figured it out:

    Code:
    [Forms]![frmViewCase].[btnViewCaseClose].SetFocus SendKeys "{Enter}"

  9. #9
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    1,360
    Unlike any other VBA event the got focus event does fire when called by VBA, so you could use the got focus event to effectively press the button for you. Make sure that the button isn't a tab stop and in theory it won't get focus any other way.

    I'm sure that ultimately this is a bit of a kludge though, and that if you described your process and the goal a better way would be possible.
    The fact that you are coding it to get focus means you can simply call its event at that point.

    Edit - I knew you would get to send keys.
    That is a bodge and is not reliable I'm afraid.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  10. #10
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    3,837
    Just spotted this thread and I've read your solution but like Minty, I'm baffled
    Maybe I'm missing the point but if all you wanted to do was run a button click from outside the form then:

    Code:
    Forms!frmViewCase.btnViewCaseClose_Click
    However you need to make the click event a Public Sub

    From inside the form
    Code:
    Me.btnViewCaseClose_Click
    If not that, then being as you've asked the question, it might help others if you could explain the point of this thread

    BTW using SendKeys is best avoided as code isn't guaranteed to work in different versions
    Colin (Mendip Data Systems) : Website, email
    If this has helped, please click the star button and leave a comment

  11. #11
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    212
    Quote Originally Posted by Minty View Post
    Unlike any other VBA event the got focus event does fire when called by VBA, so you could use the got focus event to effectively press the button for you. Make sure that the button isn't a tab stop and in theory it won't get focus any other way.

    I'm sure that ultimately this is a bit of a kludge though, and that if you described your process and the goal a better way would be possible.
    The fact that you are coding it to get focus means you can simply call its event at that point.

    Edit - I knew you would get to send keys.
    That is a bodge and is not reliable I'm afraid.
    Thanks Minty. The database I am working on has over 600 commands, last I checked. So explaining the circumstance in my situation is a mute point.

    The problem was it was being called from a main form Enter [Event procedure] for a sub form and since it was being loaded at the time during evaluation it would produce an error (similar to Error 2585) when trying to Call the event. The answer I provided bypasses this error and simulates a user clicking the close button.

  12. #12
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    212
    Thanks Ridders52. I will keep the SendKeys issue in mind and try to find a better solution later on in development. The command in my situation has to execute from a Private Sub.

  13. #13
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    212
    Anyone else interested in SendKeys Statements can find information here: https://msdn.microsoft.com/en-us/vba...keys-statement

  14. #14
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    1,360
    I have databases with 10,000 plus lines of code, 600 commands isn't relevant to your question - all we were asking for was an explanation of the immediate process surrounding this problem, not the entire database.
    If it's to do with the subform loading events what is the enter event doing that can't be achieved by some other event?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  15. #15
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    212
    The point of my 600+ commands comment was because a lot of it involves too many different things, so I was not going to explain the nuances! BTW I am sure this one is well more than 10k lines . In the end, it was a simple question. I was not looking for someone to proof read my material and "fix" things. That tends to happen on here rather than answering the original posters question. Now if someone is having issues with known working code then we provide recommendations to their architecture but, that was not my question or issue. And yes I already said I could have programmed it another way. I already knew another solution. I wanted to avoid the unnecessary hassle.
    Last edited by SierraJuliet; 01-24-2018 at 06:59 PM.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 08-22-2016, 08:57 AM
  2. Replies: 2
    Last Post: 08-27-2014, 08:19 AM
  3. Disable Mouse Right Click
    By data808 in forum Access
    Replies: 18
    Last Post: 03-10-2014, 05:58 AM
  4. Replies: 0
    Last Post: 09-27-2011, 04:27 AM
  5. Mouse click to open form
    By darryl.charles in forum Programming
    Replies: 0
    Last Post: 09-05-2008, 10:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Tech Forums: Microsoft Office Forums