Results 1 to 3 of 3
  1. #1
    journeyman is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Dec 2022
    Posts
    82

    Key Press Enter on Webbrowser control

    Hi all,



    I have a webbrowser control on a form. after much weeks of toiling to make it work, I have returned to an issue that I've found infuriating.

    I can type anything I like into the control (just like a text control), until it comes to pressing Enter.

    When I press enter, a new line is correctly created in the text, then the cursor vanishes into oblivion. Every other key works exactly as it's supposed to. What's so special about a carriage return?

    When I challenge the active control, the focus is on the WebBrowser.

    Pressing Enter makes the cursor vanish
    Pressing Shift-Enter inserts the line correctly and leaves the cursor in place.

    to be clear, pressing Enter causes the WebBrowser control to lose focus. there is no reason for it to do so - nothing in my code sends the focus away.

    I don't want to have to press Shift enter when just enter will do.

    I have tried:
    • if Keycode= 13 then KeyCode = 0 ' Prevents the keycode from triggering. Not very helpful
    • KeyCode = 13 +1 ' Enter + Shift Pressed (14)
    • KeyCode = 13 + 16 ' Enter + Shift (29)
    • SendKeys("{ENTER}") ' Causes mayhem. chaos, looped code, general crashing.
    • Searching Google ' Google got rich - I got nothing
    • Sacrificing firstborn to Athena ' Goddess of 'Tekne (Craft)' - Technology.


    None of the above worked and now I have no firstborn.

    How can I press enter and leave the cursor where it's suppose to be?

    Any ideas?

    Cheers

  2. #2
    Edgar is online now Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    274
    You can disable that behavior by going into options > client settings > move after enter > don't move
    If you want to do that programmatically, you can get the current option using:
    Code:
    Debug.Print Application.getOption("Move After Enter")
    And you can also set that option to 0, 1 or 2 by doing this:
    Code:
    Application.setOption "Move After Enter", 0
    You need 0, because 0 is "Don't Move"

    As an alternative, you can also modify your form's properties by going into > other tab > cycle > current record

    As for sendkeys, if you do this, you'll get an infinite loop, because you're basically saying "on enter, enter"
    Code:
    Private Sub wb_KeyDown(KeyCode As Integer, Shift As Integer)
        If KeyCode = 13 Then
            SendKeys "+{ENTER}"
        End If
    End Sub
    But if you add a condition to trigger it only when the two conditions are met, then all good:
    Code:
    Private someCondition As Boolean
    
    Private Sub wb_KeyDown(KeyCode As Integer, Shift As Integer)
        If someCondition = False And KeyCode = 13 Then
            keyCode = 0
            someCondition = True
            SendKeys "+{ENTER}"
        End If
    End Sub
    SendKeys has side effects, so test it well.


    If all of these fail, you'll have to use javascript, because I have no idea how to trigger a key combination without sendkeys.

  3. #3
    journeyman is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Dec 2022
    Posts
    82
    Edgar

    Always a font of wisdom

    I used
    Code:
    If KeyCode = 13 and Shift =0 then
       Call Application.setOption "Move After Enter", 0
    End if
    And it seems to work where it needs to.

    I presume I have to turn it back on somewhere, but I'm sure I can determine how that works.

    Thanks for your help.

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

Similar Threads

  1. press enter when in search box to display results
    By neill_long in forum Programming
    Replies: 4
    Last Post: 06-11-2018, 02:42 PM
  2. WebBrowser control requery
    By Historypaul in forum Forms
    Replies: 4
    Last Post: 11-12-2014, 09:09 PM
  3. WebBrowser Control to use Chrome?
    By kdbailey in forum Access
    Replies: 2
    Last Post: 07-15-2014, 11:30 AM
  4. When press enter key will log in
    By dododo in forum Forms
    Replies: 1
    Last Post: 07-17-2013, 10:58 PM
  5. sizing a url within a webbrowser control
    By Kirsti in forum Programming
    Replies: 4
    Last Post: 11-06-2012, 06:10 PM

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