sendkeys funny in access VB with runcommand accmdfind

Posted on 2006-04-21
Last Modified: 2008-01-09
Access 2002 (XP)

I have the following code to try and persuade the find dialog box to start with correct settings using sendkeys. It works (sometimes but also sets caps lock on!
Come on, Bill gates! Any ideas?

    ' do the deed
    Me.this.SetFocus             '!!! whatever the first field is for any form
    SendKeys "%ha%e%rd"   ' any part of form and field and looking down, from MS documentation
    Application.RunCommand acCmdFind


Question by:Peborgh
    LVL 44

    Expert Comment

    by:Leigh Purvis
    That's the *classic* bug with Sendkeys.

    Author Comment

    I pinched the code, incorporated into my app, compiled OK:

        ' do the deed
        Me.this.SetFocus                            '!!! whatever the (first) field is for any form
        FsendKeys "%ha%e%rd"                 ' any part of field and going down (uses a "safe" Sendkeys)
        Application.RunCommand acCmdFind

    ... and it behaves just like the original SendKeys, setting caps lock ON.

    What am I missing?

    Many thanks,

    LVL 44

    Assisted Solution

    by:Leigh Purvis
    Caps lock wasn't already on?
    I assume the API is still valid under XP (was first published some time ago - but would have come to light easily by now otherwise).

    I've never used it personally - as I don't use Sendkeys :-)

    Author Comment

    Anyone out there know of an alternative, specifiable find/findNext proc/func?

    LVL 58

    Accepted Solution


    A home-grown "Find"?

        Dim strFind As String
        strFind = InputBox("What now?", "Find")
        If strFind = "" Then Exit Sub
        strFind = Replace(strFind, "'", "''")
        With Me.RecordsetClone
            ' Find first (see below for findnext)
            .FindFirst "YourSearchField Like '*" & strFind & "*'"
            If .NoMatch Then MsgBox "huh?": Exit Sub
            Me.Bookmark = .Bookmark
        End With

    Find next:
            .Bookmark = Me.Bookmark
            .FindNext "YourSearchField Like '*" & strFind & "*'"

    To have a combination of find first / find next buttons, the best is to store the search criteria in a global variable as a whole:

        gstrCriteria = "YourSearchField Like '*" & strFind & "*'"

    Finally, if you feel adventurous, it's quite easy to rewrite the entire "Find" dialog as a custom pop-up form.


    Author Comment

    Getting back to the subject in hand, mySendKeys does work!! I was using Fsendkeys and that acted in the uncorrected way. Blame Bill gates.
    So thanks to LPurvis for his help on sendkeys and (oVo) for his finding substiture - that knowledge was useful also.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
    In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    779 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

    12 Experts available now in Live!

    Get 1:1 Help Now