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!