Consulting

Results 1 to 3 of 3

Thread: setfocus not working

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Feb 2018
    Posts
    2
    Location

    setfocus not working

    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.
    Attached Files Attached Files
    Last edited by SamT; 02-09-2018 at 11:37 AM. Reason: Reason for needing setfocus

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •