TextBox setfocus unexpected call

Ziggy12

Active Member
Joined
Jun 26, 2002
Messages
365
I've got a user form with 12 textbox, one for each month a total textbox number 13 and a 14th text box (TB28) to enter $'s in.

AfterUpdate in each textbox 1-12 posts its value to a worksheet all values are summed in a =sum range which in turn populates textbox 13. When TB13.text = 100.00 it sucessfully calls a number of routines but what I can't get it to do is set focus on TB28.

Private Sub TextBox13_Change()
If TextBox13.Text = "100.00" Then
With FormPhasedAmt.TextBox28
.SelStart = 0
.SelLength = Len(TextBox28.Text)
.SetFocus
End With
End If
End Sub

It returns a Run time error Unexpected call to method or property access highlighting .SetFocus. The rest of the code works OK. Is it because other textbox on the same user form have text highlighted because of the tab order?

cheers
Ziggy
 
Neat, that's two similar text things I learned this week.

.SelText and the Mid statement (vs. Mid function)

Cool.

Ziggy, have you tried setting the EnterFieldBehaviour to SelectAll?
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Mike

Glad you seem to have learned something - but I would actually suggest you sort of unlearn it.

These methods and properties are useful in some circumstances but as far as I'm concerned they aren't really that useful.

I know there will be a lot of people out there that will disagree, but that's my opinion.

It's still not clear what Ziggy, the OP, is trying to do - to me anyway.

It seems like things might be overcomplicated - multiple events, multiple controls etc.

But, hey what do I know.:)
 
Upvote 0
Every new thing I learn is a temptation to do the wrong thing. Specificaly, the .SelText would help me use the KeyPress event to validate text box entry. (Dangerous territory, involving the question "What could the user possibly do?")

I hold that virtue lies in resisting temptation, rather than being unaware of it. :)
 
Upvote 0
Yep doesn't make any difference. Have googled the problem seems its more to do with the order controls are put on a form.

Ziggy
 
Upvote 0
Ziggy

The order you put the controls on the form shouldn't make a difference.

If you want to change the order the controls get focus then you should probably look into Tab Order.

But I still don't see why you are using all these different events.

It just doesn't seem to make sense and actually appears to be causing problems.:)
 
Upvote 0
Hi Ziggy,

Try to add .Enabled = True before .SetFocus
If Textbox28 is into the Frame then check the same .Enabled = True for the Frame.

Regards,
Vladimir
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,964
Messages
6,175,659
Members
452,666
Latest member
AllexDee

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