ENTER or TAB key to trigger event in UserForm

03856me

Active Member
Joined
Apr 4, 2008
Messages
297
This code is working perfectly when the ENTER key is used. My user would like to use the TAB key most times since she uses the tab key on her primary program and it has become a habit. I have multiple folks using this program and some want the ENTER key and some the TAB key. Can this code be modified to accept either ENTER or TAB to trigger the event?

Code:
Private Sub cbo_InOut_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    cbo_InOut.BackColor = &HFFFFFF
    If cbo_InOut.Value = "I" Then
        Me.txt_ibS4S.Visible = True
        Me.txt_ibRGH.Visible = True
        Me.txt_ibfullpanel.Visible = True
        Me.txt_ibhalfpanel.Visible = True
        Me.txt_ibpanelftg.Visible = True
        Me.txt_rateIBs4s.Visible = True
        Me.txt_rateIBrgh.Visible = True
        Me.txt_rateIBfull.Visible = True
        Me.txt_rateIBhalf.Visible = True
        Me.txt_IBs4sINCOME.Visible = True
        Me.txt_IBrghINCOME.Visible = True
        Me.txt_IBfullINCOME.Visible = True
        Me.txt_IBhalfINCOME.Visible = True
        Me.lbl_ibs4s.Visible = True
        Me.lbl_ibrgh.Visible = True
        Me.lbl_ibfullpanel.Visible = True
        Me.lbl_ibhalfpanel.Visible = True
        Me.lbl_ibpanelftg.Visible = True
        Me.lbl_inbound.Visible = True
        Me.txt_obtruck.Value = ""
        Me.txt_obcar.Value = "0"
        Me.txt_obfootage.Value = ""
        Me.txt_obpanelftg.Value = ""
        Me.txt_obdtruck.Value = ""
        Me.txt_obdpanelftg.Value = ""
        Me.txt_obdlumberftg.Value = ""
        Me.txt_OBtruckINCOME.Value = ""
        Me.txt_OBDtruckINCOME.Value = ""
        
        Me.txt_obtruck.Visible = False
        Me.txt_obcar.Visible = False
        Me.txt_obfootage.Visible = False
        Me.txt_obpanelftg.Visible = False
        Me.txt_rateOBtruck.Visible = False
        Me.txt_OBtruckINCOME.Visible = False
        Me.lbl_obtruck.Visible = False
        Me.lbl_obcar.Visible = False
        Me.lbl_obfootage.Visible = False
        Me.lbl_obpanelftg.Visible = False
        Me.lbl_outbound.Visible = False
        
        Me.txt_obdtruck.Visible = False
        Me.txt_obdpanelftg.Visible = False
        Me.txt_obdlumberftg.Visible = False
        Me.txt_rateOBDtruck.Visible = False
        Me.txt_OBDtruckINCOME.Visible = False
        Me.lbl_obdtruck.Visible = False
        Me.lbl_obdpanelsftg.Visible = False
        Me.lbl_obdlbrftg.Visible = False
        Me.lbl_obdunn.Visible = False
    Else
        If cbo_InOut.Value = "O" Then
        Me.txt_obtruck.Visible = True
        Me.txt_obcar.Visible = True
        Me.txt_obfootage.Visible = True
        Me.txt_obpanelftg.Visible = True
        Me.txt_rateOBtruck.Visible = True
        Me.txt_OBtruckINCOME.Visible = True
        Me.lbl_obtruck.Visible = True
        Me.lbl_obcar.Visible = True
        Me.lbl_obfootage.Visible = True
        Me.lbl_obpanelftg.Visible = True
        Me.lbl_outbound.Visible = True
        
        Me.txt_ibS4S.Value = ""
        Me.txt_ibRGH.Value = ""
        Me.txt_ibfullpanel.Value = ""
        Me.txt_ibhalfpanel.Value = ""
        Me.txt_ibpanelftg.Value = ""
        Me.txt_IBs4sINCOME.Value = ""
        Me.txt_IBrghINCOME.Value = ""
        Me.txt_IBfullINCOME.Value = ""
        Me.txt_IBhalfINCOME.Value = ""
        
        Me.txt_ibS4S.Visible = False
        Me.txt_ibRGH.Visible = False
        Me.txt_ibfullpanel.Visible = False
        Me.txt_ibhalfpanel.Visible = False
        Me.txt_ibpanelftg.Visible = False
        Me.txt_rateIBs4s.Visible = False
        Me.txt_rateIBrgh.Visible = False
        Me.txt_rateIBfull.Visible = False
        Me.txt_rateIBhalf.Visible = False
        Me.txt_IBs4sINCOME.Visible = False
        Me.txt_IBrghINCOME.Visible = False
        Me.txt_IBfullINCOME.Visible = False
        Me.txt_IBhalfINCOME.Visible = False
        Me.lbl_ibs4s.Visible = False
        Me.lbl_ibrgh.Visible = False
        Me.lbl_ibfullpanel.Visible = False
        Me.lbl_ibhalfpanel.Visible = False
        Me.lbl_ibpanelftg.Visible = False
        Me.lbl_inbound.Visible = False
      End If
    End If
End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Actually, in thinking about it - I probably need the TAB or ENTER key option for the entire UserForm, is this possible in the Initialize event or would it have to be code added to each textbox, combo box, etc.?
 
Upvote 0
The default behaviour of the TAB key on a userform is to exit the current control and goto the next one.

The code you posted is triggered when cbo_InOut is exited, so it should run when the user presses TAB, or ENTER.

If that's not happening then something else must be going on.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,598
Members
449,089
Latest member
Motoracer88

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