0

Currently I've attached a function to a command button on my form which retrieves what the user inputs into the textbox on the form; this works fine but I want to emulate this behaviour with the ENTER key. How can I go about doing this?

I tried the Enter Property on the textbox but that only occurs when focus has been transfered to the textbox, not when i press enter after input.

I've read about the KeyUp event for VB but there's got to be an easier way - I've googled this but can't find what Im looking for. Any suggestions?

Thanks

Katana24
  • 8,706
  • 19
  • 76
  • 118
  • Have you looked at after update event? – Fionnuala Jan 16 '13 at 15:09
  • No - I imagined that it should respond on default to the enter key being pressed. I'll examine that now – Katana24 Jan 16 '13 at 15:19
  • After Update is not enter only, it is after you leave the textbox by any means when you have changed data. It all depends in what you are doing. – Fionnuala Jan 16 '13 at 15:26
  • The main target here is when the enter button is pressed - would after update suffice? – Katana24 Jan 16 '13 at 15:29
  • I need to know what you are doing before I can give a suitable answer. On the information you have given, all I can do is guess at possibilities. – Fionnuala Jan 16 '13 at 15:31
  • 1
    look at the `Default` and `Cancel` properties of the button. Default executes the button click event occur on , and Cancel executes the Click event on – SeanC Jan 16 '13 at 15:32
  • Ok - User enters some text into the text box on the form and presses enter - once enter is pressed it should launch some function to handle the input – Katana24 Jan 16 '13 at 15:43
  • @Sean Cheshire will examine that now – Katana24 Jan 16 '13 at 15:44
  • 1
    If the function occurs for the textbox, you want after update, if the function occurs for the command button, look at @SeanCheshire's comment. Please always provide a fairly detailed question. – Fionnuala Jan 16 '13 at 16:00
  • @Remou sorted now - when with your suggestion of the after update. If you write this as an answer I ll accept it – Katana24 Jan 17 '13 at 13:41

1 Answers1

1

In many cases, the After Update event is suitable for working with data entered into a textbox, for example:

Private Sub txtFilter_AfterUpdate()
    Me.Filter = "Content " & Me.txtFilter.Text
    Me.FilterOn = True
End Sub

However, if you need to edit or validate the data, Before Update is more suitable.

Private Sub txtText_BeforeUpdate(Cancel As Integer)
    If Me.txtText = "Invalid" Then
        Me.Undo
        Cancel = True
    End If
End Sub
Fionnuala
  • 90,370
  • 7
  • 114
  • 152