+ Reply to Thread
Results 1 to 6 of 6

keypresses being passed from user form to worksheetn

Hybrid View

  1. #1
    Registered User
    Join Date
    08-25-2015
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    30

    keypresses being passed from user form to worksheetn

    Hi,

    I have two user forms in my spreadsheet that are launched by pressing a keystroke.
    I want both of them to activate the search button located in each when I press the enter key. I have set the default button property for the search button to true on both forms.
    However, this is unreliable. I have a few cells in my worksheet that have hyperlinks and if I load one of the forms when the keyboard focus is in one of these cells and then press enter when the user form is active, it activates the hyperlink in the worksheet instead.
    Sometimes it will activate the default button on my user form but it is unreliable. How do I stop keypresses from being passed to the underlying worksheet? This is the code I am using to load the forms:


    If Not frmPlaceSearchDialog.Visible Then
    frmPlaceSearchDialog.Show vbModal
    End If

  2. #2
    Forum Contributor
    Join Date
    01-08-2016
    Location
    Cagayan De Oro City, Philippines
    MS-Off Ver
    2013
    Posts
    152

    Re: keypresses being passed from user form to worksheetn

    Hi, its a little hard to visualize what you are pressing and if your pressing it on a form or a worksheet, so a little more info would go a long way.

    but for now, you can check a range if it contains hyperlinks and act accordingly

    Private Sub Worksheet_Change(ByVal Target As Range) 
        If Target.Hyperlinks.Count > 0 Then
            MsgBox "Has Hyperlink"
        End If
    End Sub
    this maybe useful in your case but it would be better if you can send more information clearly describing the process you code it going through.

    Thanks

  3. #3
    Registered User
    Join Date
    08-25-2015
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    30

    Re: keypresses being passed from user form to worksheetn

    Hi gbeats101,
    I have a user form with text fields and combo boxes in it. I want to be able to press the enter key and for it to activate the search button located on the form. I have set the default button property for the search button to true.

    However, when I press the enter key when in the user form, it gets passed through to the underlying worksheet. The search button is activated sometimes but sometimes it isn't.

    I want to stop the enter key from being passed through to the underlying worksheet when I press it in any of the text boxes and combo boxes in my user form.

  4. #4
    Forum Contributor
    Join Date
    01-08-2016
    Location
    Cagayan De Oro City, Philippines
    MS-Off Ver
    2013
    Posts
    152

    Re: keypresses being passed from user form to worksheetn

    im still not sure exactly what is happening here........

    looking back at your first post, it looks like you have a form that is open modal and if the focus is set to the worksheet and the user presses enter on a cell in the worksheet then you want to.....activate your button...(make it visible, run the code as if it was pressed..be very clear)

    now looking at your second post......what is the default button property? how is pressing enter when the focus is on your form affecting the worksheet if your not telling it to do that, unless your trying to capture something your typing in the formula bar while in edit mode which (i have not tested but) may force excel out of edit mode applying the changes before processing the enter key......

    you need to be very specific on what is happening, step by step so we can get this whole picture. something doesnt quite add up here.

  5. #5
    Registered User
    Join Date
    08-25-2015
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    30

    Re: keypresses being passed from user form to worksheetn

    Hi gbeats101,

    To launch my form, I press the keystroke Ctrl + P in excel.
    When the form loads, the focus is in a text box control.
    If I type in the text box and press enter, it should activate the default button which is set to the search button located on the form.
    However, the enter key seems to get passed through to the underlying worksheet and doesn't activate the search button reliably. I have to use the accelarator key (alt + s) to activate the search button or tab to the search button and press enter.

    I'm blind and using some screen reading software. I have been doing some more testing and I think it may have something to do with that and it not changing the focus from the worksheet to the form when the user form is launched. If I press alt + tab to move away from Excel and back again then pressing the enter key works as expected.



    Quote Originally Posted by gbeats101 View Post
    im still not sure exactly what is happening here........

    looking back at your first post, it looks like you have a form that is open modal and if the focus is set to the worksheet and the user presses enter on a cell in the worksheet then you want to.....activate your button...(make it visible, run the code as if it was pressed..be very clear)


    now looking at your second post......what is the default button property? how is pressing enter when the focus is on your form affecting the worksheet if your not telling it to do that, unless your trying to capture something your typing in the formula bar while in edit mode which (i have not tested but) may force excel out of edit mode applying the changes before processing the enter key......

    you need to be very specific on what is happening, step by step so we can get this whole picture. something doesnt quite add up here.

  6. #6
    Forum Contributor
    Join Date
    01-08-2016
    Location
    Cagayan De Oro City, Philippines
    MS-Off Ver
    2013
    Posts
    152

    Re: keypresses being passed from user form to worksheetn

    Ah ok, i can only assume that your form is loosing focus somewhere, i ran a small test to see if i can get this behavior and i could not. is there any code running when you make changes on the textbox?

    are you updating anything on the sheet from the form if you type in the textbox?

    Can you recreate this behavior anytime and is it possible to have someone look at the screen while it happens, or send the file here so i can look at it?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Populating any combo box on any user form through passed parameters
    By insomniac53 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-28-2015, 03:59 AM
  2. [SOLVED] User Form to execute search and return all values to the user form for editing
    By allwrighty in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-11-2013, 10:40 PM
  3. [SOLVED] Excel vba user form- open directly to user form not worksheet
    By PANTECH in forum Excel Programming / VBA / Macros
    Replies: 26
    Last Post: 04-24-2013, 05:07 PM
  4. [SOLVED] Excel user form- If/Then statement outcome to show on user form
    By PANTECH in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-18-2013, 09:16 AM
  5. Help to summarize data from multiple cells within a worksheetn onto a master
    By cellachdean in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-08-2013, 07:38 PM
  6. Differentiate keypresses in Worksheet_SelectionChange event
    By Mervil in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-08-2010, 03:59 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1