problem with setfocus

mkc745

New Member
Joined
Mar 28, 2014
Messages
2
I'm having problems with setting focus on a text box from a textbox_change() event.
What I want to happen is when the text in the box gets to a certain length it triggers an event, clears the text box and sets the focus back on the now blank text box.
Here's the code:

Private Sub InputTextBox_Change()


If Len(InputTextBox.Value) = 28 Then


Sheets("Scans").Cells(FirstEmptyRow("Scans"), 1).Value = Mid(InputTextBox.Value, 18, 5)
InputTextBox.Value = ""
Update
InputTextBox.SetFocus


End If
End Sub

FirstEmptyRow and Update are both functions which I have defined elsewhere.

It might be helpful to note that this runs fine on one laptop running an older version of excel but we recently got a new computer running Windows 8 with Excel 2013 and now it doesn't work. It will do everything except setting the focus back on the text box. Instead it acts as if someone has pressed tab and selects the next element in the userform.

Thanks!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
First thing I would try is to simply delete the InputTextBox.SetFocus line. I haven't tested it but it probably already has focus no?
 
Upvote 0
First thing I would try is to simply delete the InputTextBox.SetFocus line. I haven't tested it but it probably already has focus no?

I figured it out. I've been working on this program mostly independently but someone had changed the MaxLength property of the InputTextBox to 28. Once I changed it back to 0 it worked perfectly. Annoying.
Thanks!
 
Upvote 0

Forum statistics

Threads
1,215,143
Messages
6,123,275
Members
449,093
Latest member
Vincent Khandagale

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