Cannot Activate ActiveX Textbox

Pyrgos

New Member
Joined
Feb 22, 2012
Messages
30
Hello there,

I have the following code on an ActiveX Listbox stating that if I press Shift+Tab, a Textbox will be activated. The trouble is, it won't activate, and I find it very weird. SetFocus is not possible to use. Here is the code:

Code:
Private Sub lstSearch_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = vbKeyReturn Then
    txtSearch.Activate
    Call DoTheMagic(lstSearch.List(0))
ElseIf Shift = 1 And KeyCode = vbKeyTab Then
    lstSearch.Selected(0) = False
    txtSearch.Activate ‘IT DOES NOT ACTIVATE, IT ONLY DESELECTS THE LISTBOX
End If
End Sub

If I take the Tab key from the code and set the condition to activate the textbox in case of pressing the Shift key only, then txtSearch will be activated successfully:

Code:
Private Sub lstSearch_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = vbKeyReturn Then
    txtSearch.Activate
    Call DoSteamMagic(lstSearch.List(0))
ElseIf Shift = 1 Then
    lstSearch.Selected(0) = False
    txtSearch.Activate ‘IT WILL ACTIVATE WITH SUCCESS
End If
End Sub

Setting the TAB key only instead of Shift+TAB has the same result.

Any ideas on how can I get this working?

Thank you in advance.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hello

- Maybe it has to do with the fact that tab is used to cycle through the controls
- Excel 2007 won’t let me use the activate method with the text box
- The following code presents three ways to go from the list box to the text box: pressing return, shift + tab or shift + up arrow

Code:
' this code goes at the UserForm module


Private Sub lstSearch_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift%)
If KeyCode = vbKeyReturn Then
    txtSearch.SetFocus
    MsgBox "done with return key"
 ElseIf KeyCode = vbKeyUp And Shift = 1 Then
    txtSearch.SetFocus
    MsgBox "done with shift + up arrow key"
End If
End Sub


Private Sub UserForm_Initialize()
Me.lstSearch.List = Split("Grete/Ingrid/Joan/Lisa/Alberto", "/")
Me.lstSearch.TabIndex = 1
Me.txtSearch.TabIndex = 0
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,941
Members
449,094
Latest member
teemeren

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