VB:Private Sub UserForm_Activate() TextBox1.SetFoucus End Sub
To accomplish whats in the title, I tried (and think I used successfully previously) the following code:
Some details, i have a userform named Findform, a textbox in it named tbFind, and the above code is in the userform initialization event section.VB:With tbfind .SelStart = 0 .SelLength = Len(.Value) .SetFocus End With
Oh also, I dont get any error, everything runs just fine, its just the cursor is not inside the textbox waiting for typing in it. (but i do think it is the focus, when i press tab it goes to the next one in the tab order)
Looking for any ideas why i may run into problems with this. Thanks!
I tried sticking that line into userform_activate, spelled correctly though of course, to no avail =(
Oh i also forgot to mention in the original post, the textbox is on a multipage. Maybe that affects it somehow? I have controls inside and outside of the multipage.
Also i used
which is the page that the tbFind box is on.VB:FindForm.MultiPage1.Value = 0
If there is any text in the box, the cursor will not appear. The code requries that the whole contents be hightlighted rather than the cursor put in a particular location. To make the cursor appear
VB:TextBox1.SelLength = 0
Well I gave that a shot, it did not work as well I was thinking it wouldn't, because
I appreciate the suggestion though!VB:textbox1.SelLength = 0 'is the same thing as textbox1.SelLength = Len(textbox1.Value) 'if textbox1 is clear of text
I'm thinking its possibly something screwy with Vista and xl2000, or more likely some bad code/design somewhere that affects it for some reason. I was just hoping maybe someone had the same problem.
What EXACTLY do you want to do? "did not work" is a helpful as telling the DR you don't feel well.
Isolating the simple code to a userform with Textbox1 on page 1 of a multipage control... the code works fine.
There's something else in your code/form that's causing your problem.
Sub All_Macros(Optional control As Variant)
Sorry, I will be more explicit. The whole project is basically an attempt at rewriting the find feature of Excel, to make my older excel version more to my liking when using it. I'll write it in code with comments explaining what i'm expecting.Originally Posted by Dave Hawley
VB:'press hotkey to start the addin: Sub MyFindAll() FindForm.Show End Sub 'this fires the initialization: Private Sub UserForm_Initialize() With cboxLookIn .AddItem "Formulas" .AddItem "Values" .AddItem "Comments" .Value = "Formulas" End With With cboxSearchScope .AddItem "Worksheet" .AddItem "Selected cells" .AddItem "Entire Workbook" .Value = "Worksheet" End With With cboxMatch .AddItem "Entire cell" .AddItem "Any part of cell" .ListIndex = 1 End With lbFound.ColumnWidths = 50 bReplaceAll = False FindForm.MultiPage1.Value = 0 With tbFind .SelStart = 0 .SelLength = Len(.text) .SetFocus End With End Sub 'when the userform shows after this code, I am expecting 'the blinking cursor prompt to be inside the textbox named '.tbFind. This doesnt happen.Thanks for the suggestion, I should have tried isolating it like that before I posted. Having said that, I did try now, and it still does not put the cursor into the textbox. I did:Originally Posted by Aaron Blood
Also just want to add, using the above test, when the Userform showed and the cursor wasnt in the textbox, I clicked on page 2, then clicked back to page 1 immediately, the cursor did go inside the textbox1.VB:'I have a new, blank workbook. I placed a form in it named Userform1. 'I placed a MultiPage named MultiPage1 within it. I placed a textbox 'named Textbox1 within the multipage. The code is as follows: Private Sub UserForm_Initialize() TextBox1.SelStart = 0 TextBox1.SelLength = Len(TextBox1.Text) TextBox1.SetFocus End Sub 'i also tried placing the same code within the Activation event, so it 'was in both events at the same time, to no avail.
Some follow up to this issue. Thinking about this factso I made some changes to the code. I removed all the setfocus code from the initialization event, and anywhere else within the project. I changed my simple procedure code to show the userform (and trigger the initialization) as followsOriginally Posted by Discodrew
And strangely enough, this does the trick. There is no setfocus anywhere within the code, and I dont have any multipage_change event code. Upon loading and showing the userform, the cursor is now in the textbox awaiting the user to type. voilaVB:'it was: Sub MyFindAll() FindForm.Show End Sub 'now it is Sub MyFindAll() FindForm.Show FindForm.MultiPage1.Value = 1 FindForm.MultiPage1.Value = 0 End Sub
There are currently 2 users browsing this thread. (0 members and 2 guests)