Event types

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,347
Office Version
  1. 365
Platform
  1. Windows
Which event type would be initiated when the User hits the Enter Key? Is it "On Enter", "After Update"... Also what about the Tab key. If I wanted an event like go to a form after they hit the Tab Key or Enter Key, which one of the Events should I use. The MS Online help isn't very clear
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi Gheyman

9 is tab
13 is enter
27 is escape
32 is space

The code below is for a control. In this particular case, I'm using it on a Listbox. I wanted the users to be able to press the space bar or hit enter to make a choice. I also wanted them to be able to hit escape to exit the form.

Code:
Private Sub Found_lb_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
  If KeyAscii = 32 Or KeyAscii = 13 Then
    Call ok_btn_Click
  ElseIf KeyAscii = 27 Then
    Unload RoleChooser
  End If
  
End Sub
 
Upvote 0
If you use the after_update event you'll capture anything where the user has just updated (put something into) a field. Generally that's best (unless you want to potentially validate/cancel the entry, when you need before_update).

Handling key events is complicated and to be avoided if possible. Unless you like getting involved in a lot of nitty gritty details. As an example. Someone might enter a value in a field, then use their mouse to go to another part of the form. So no key events will be capture, since no key was pressed.
 
Upvote 0
Which event type would be initiated when the User hits the Enter Key? Is it "On Enter", "After Update"... Also what about the Tab key. If I wanted an event like go to a form after they hit the Tab Key or Enter Key, which one of the Events should I use. The MS Online help isn't very clear


I would avoid trying to re-purpose the standard functionality of these keys.


I recommend using the built-in functionality of Access to go what you need whenever possible.

Trick: Use the command button's default property.

It is simple to set it up to use the Enter key to open another form. Create a command button to open the other form. Set the command button's (other tab) default property to yes. Done.
 
Upvote 0

Forum statistics

Threads
1,221,707
Messages
6,161,416
Members
451,705
Latest member
Priti_190

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top