Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-27-2019, 05:58 AM
jrooney7 jrooney7 is offline SetFocus command being ignored Windows 7 64bit SetFocus command being ignored Office 2013
Novice
SetFocus command being ignored
 
Join Date: Sep 2018
Posts: 23
jrooney7 is on a distinguished road
Default SetFocus command being ignored

Hello all, I have a userform containing several textboxes and comboboxes. I have the below code that executes on the exit of one combobox and inserts text into a textbox in the userform while it is still active. I also have code that allows that textbox to grow as text is entered. Upon exiting the combobox, I am getting an error for the LineCount property (in the textbox growing code) stating that the textbox needs the focus. But the first line of the textbox growing code is the SetFocus command and it does not seem to be reading it. I also put the SetFocus command in the exit code for the combobox, thinking it was the link that was the problem. Here is my code for the ComboBox exit:



Code:
Private Sub FirearmTypeComboBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)

    ResultsTextBox.SetFocus
   
    If RestorationTypeComboBox.Value = "Successful Restoration" Then
        ResultsTextBox.Value = "Examination and [magnetic and/or chemical] processing of the aaa bbb restored the original obliterated serial number which was determined to be 'ccc'."
        ResultsTextBox.Text = Replace(ResultsTextBox, "aaa", ItemComboBox.Value)
        ResultsTextBox.Text = Replace(ResultsTextBox, "bbb", FirearmTypeComboBox.Value)
        ResultsTextBox.Text = Replace(ResultsTextBox, "ccc", RestoredCharactersTextBox.Value)
    End If
    
    If RestorationTypeComboBox.Value = "Partial Restoration" Then
        ResultsTextBox.Value = "Examination and [magnetic and/or chemical] processing of the aaa bbb partially restored the original obliterated serial number which was determined to be 'ccc'."
        ResultsTextBox.Text = Replace(ResultsTextBox, "aaa", ItemComboBox.Value)
        ResultsTextBox.Text = Replace(ResultsTextBox, "bbb", FirearmTypeComboBox.Value)
        ResultsTextBox.Text = Replace(ResultsTextBox, "ccc", RestoredCharactersTextBox.Value)
    End If
    
    If RestorationTypeComboBox.Value = "Unsuccessful Restoration" Then
        ResultsTextBox.Value = "Examination and [magnetic and/or chemical] processing of the aaa bbb failed to restore any part of the serial number."
        ResultsTextBox.Text = Replace(ResultsTextBox, "aaa", ItemComboBox.Value)
        ResultsTextBox.Text = Replace(ResultsTextBox, "bbb", FirearmTypeComboBox.Value)
    End If
    
    ResultsTextBox.SetFocus
    
End Sub
Here is the code for allowing the textbox to grow in the userform:

Code:
Private Sub ResultsTextBox_Change()
    
    ResultsTextBox.SetFocus
    'the line below is where the debug directs me
    If ResultsTextBox.LineCount > 1 Then
        ResultsTextBox.Height = ((ResultsTextBox.LineCount - 2) * 13.5) + 33
        With ResultsTextBox
            .SelStart = 0
            .SelStart = Len(.Text)
        End With
        
        SNRCommandButton.Top = ResultsTextBox.Top + ResultsTextBox.Height + 22.5
        SNRUserForm.ScrollHeight = SNRCommandButton.Top + SNRCommandButton.Height + 28
    End If
    
    If ResultsTextBox.LineCount = 1 Then
        ResultsTextBox.Height = 19.5
        SNRCommandButton.Top = ResultsTextBox.Top + ResultsTextBox.Height + 22.5
        SNRUserForm.ScrollHeight = SNRCommandButton.Top + SNRCommandButton.Height + 28
    End If

End Sub
If I remove the code for the exit of the combobox, the linecount code works fine and the textbox grows properly. It seems like it should work, and it has in the past, but for some reason I get the error every time now. Help!
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Show table list by using chek box command and save document on sharepoint by using command button Zhibek Word VBA 3 08-16-2018 06:19 PM
How do I use the Go To command? Jbee PowerPoint 3 12-06-2017 08:39 AM
Add Command to Bar neiljsalkind Excel 0 02-03-2012 08:31 AM
.setfocus not working why? Cbrehm Excel Programming 0 05-11-2011 02:52 AM
Add-In:How to add command right click command bar phang Outlook 0 01-15-2007 02:53 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:32 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft