Results 1 to 3 of 3
  1. #1
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109

    Sendkeys On Form Open

    Hi Guys,


    VB Project of the database I created is password protected. This means that I have to unlock it in order to programitically add code to e.g. form. I found somewhere such a code that uses SendKeys method to provide the password so new code can be added. The "unlock" code is as follows:


    Code:
    Dim Password as string
    Password = "xxxx"
    SendKeys "%{F11}", True
    SendKeys "%TE+{TAB}{RIGHT}%V{+}{TAB}", True 
    SendKeys Password, True
    SendKeys "~", True
    SendKeys "{ESC}", True
    SendKeys "%{F11}"



    This code does the job well when run from e.g. form's button. Unfortunately I have to run it from form_open event. In such case this code doesn't work. It should send "ALT+F11" to display vba project window, then should send "%TE+{TAB}{RIGHT}%V{+}{TAB}" to display password prompt, send password and send enter key. It doesn't work, though, when triggered from form_open event. Why doesn't it work? How can I work around it?


    PS. I know SendKeys is very unreliable method but there's no other way. This topic is not to post how unreliable it is and "why do I use it" questions...


    Regards,
    Robert

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    If I had to guess, in the open event focus doesn't move to the VBA window as expected, since the form is still opening. Would putting it in the timer event so it ran right after the form opened work?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    robs23 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    109
    Yeah I know sendKeys is evil, but I thought it was necessary evil in that case. Fortunately I was wrong. The main reason I decided to go into adding procedures during runtime was that I thought it's the only way of handling control's events from object. In other words, I didn't want to assign object method (cls.refreshResults(keyword as string)) to textbox's change event for every form where I use search object. I wanted to create the object on form's load and kill it on form's close. Of course I could assign public function to e.g. textbox.onChange = method, but it wasn't always the case. Fortunately I came across WithEvents way of doing. I must say it was the missing link for me, now I can handle form's/control's events from custom object without having to add them separately every time.


    Thanks for efforts.
    Robert

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

Similar Threads

  1. Sendkeys and Utility Add-Ins
    By steve.redman in forum Access
    Replies: 12
    Last Post: 12-13-2013, 02:31 PM
  2. sendkeys, anyone have experience?
    By redbull in forum Programming
    Replies: 1
    Last Post: 02-14-2013, 10:44 AM
  3. Keydown and SendKeys
    By Remster in forum Programming
    Replies: 10
    Last Post: 08-10-2011, 10:39 AM
  4. Sendkeys replacement
    By numberguy in forum Programming
    Replies: 6
    Last Post: 07-14-2011, 08:29 AM
  5. Sendkeys replacement
    By numberguy in forum Forms
    Replies: 3
    Last Post: 10-29-2010, 07:20 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
  •  
Other Forums: Microsoft Office Forums