• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Activate Search button when press enter on form

Tom A

Member
Hi,

I've got a user form that I'm using to search my workbook. I would like to be able to press the enter key on any control on the form and for it to activate the search button.

When the form is initialised, I am setting the focus to a text box on the form and the default button property of the search button is set to true.
However, it isn't always activating the Search button reliably when I press enter. The form is modal but it doesn't seem to get the focus properly as sometimes when I press enter, it activates the active cell in the active worksheet.
This form is based on another form in my workbook which works fine.
I have set an accelarator key of Alt + S for the search button so am using that to activate the search button which works reliably but would like to be able to press the enter key.

Any suggesions will be appreciated,
Thanks,
 
Hi Kmahraz, Thanks, I was about to export and attach the form to this post but I've noticed, it works fine when I press F5 and launch it from the VBA editor or from the macro list by pressing Alt + F8. The problem occurs when I launch it from any worksheet using a shortcut key. I'm using Ctrl + shift + e. I don't know if that is associated with something else in Excel?

I can try attaching the form if this isn't of any help. The following is the code used to launch it when I press the shortcut key. It is the same for the other forms in my project:


Code:
Sub ShowSearchDialog()
  If Not frmSearchDialog.Visible Then
  frmSearchDialog.Show vbModal
  End If
End Sub


@Tom A
Can you make your file available to the forum and we will look at it.

Best,
K
 
Last edited by a moderator:
Back
Top