After scouring the web for reasons why textbox.setfocus was not working I tried this and it worked. I am posting here to reach a wider audience. This is done in Solidworks and some of the events are not available that were used in other solutions. I tried KeyUp but that did not help. I attached the form and copied the code below, including remarked 'code that did not work:
Private Sub TextBoxPartNumber_KeyDown(ByVal KeyCode As msforms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = vbKeyReturn Then 'vbKeyReturn=13
Dim bl As Boolean
Dim Item1(0 To 4) As Variant
Dim CFList As Control ' has list of stock numbers to process
Set CFList = Me.ListBoxPartsList
Item1(0) = Me.TextBoxPartNumber.Value
If Item1(0) = "" Then
CommandButtonMakePdfs.SetFocus
SendKeys "[ENTER]" 'start making files if user hits enter on empty text box
Else
bl = AddtoSelectList(Item1, CFList) ' search list, don't add if it's already there
If bl = True Then '161230'
CFList.Selected(CFList.ListCount - 1) = True '180209'
End If
End If
Exit1:
'Me.TextBoxPartNumber.SetFocus
KeyCode = 0 '180209'
Me.TextBoxPartNumber.Value = ""
'Me.TextBoxPartNumber.SelStart = 0
'SendKeys "{TAB}{TAB}" ' get back to the textbox
On Error Resume Next
Erase Item1
Set CFList = Nothing
End If
End Sub
edit: The user types text then presses enter to add the line item to the list box below and continues typing a new line item without having to click back into the box.