Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 9 of 9

Thread: Put/Place Cursor Into UserForm TextBox

  1. #1
    Join Date
    5th June 2008
    Posts
    14

    Put/Place Cursor Into UserForm TextBox

    To accomplish whats in the title, I tried (and think I used successfully previously) the following code:

    VB:
    With tbfind 
        .SelStart = 0 
        .SelLength = Len(.Value) 
        .SetFocus 
    End With 
    
    
    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.

    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!

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    24th January 2003
    Location
    Australia
    Posts
    31,717

    Re: Putting Cursor Into A Userform Textbox With Vb

    VB:
    Private Sub UserForm_Activate() 
        TextBox1.SetFoucus 
    End Sub 
    
    

  3. #3
    Join Date
    5th June 2008
    Posts
    14

    Re: Put/Place Cursor Into UserForm TextBox

    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
    VB:
    FindForm.MultiPage1.Value = 0 
    
    
    which is the page that the tbFind box is on.

    Thanks

    Excel Video Tutorials / Excel Dashboards Reports


  4. #4
    Join Date
    23rd April 2007
    Posts
    3,475

    Re: Put/Place Cursor Into UserForm TextBox

    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 
    
    

    Excel Video Tutorials / Excel Dashboards Reports


  5. #5
    Join Date
    5th June 2008
    Posts
    14

    Re: Put/Place Cursor Into UserForm TextBox

    Well I gave that a shot, it did not work as well I was thinking it wouldn't, because
    VB:
    textbox1.SelLength = 0 
     'is the same thing as
    textbox1.SelLength = Len(textbox1.Value) 
     'if textbox1 is clear of text
    
    
    I appreciate the suggestion though!

    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.

    Excel Video Tutorials / Excel Dashboards Reports


  6. #6
    Join Date
    24th January 2003
    Location
    Australia
    Posts
    31,717

    Re: Put/Place Cursor Into UserForm TextBox

    What EXACTLY do you want to do? "did not work" is a helpful as telling the DR you don't feel well.

  7. #7
    Join Date
    10th February 2003
    Location
    Palm Beach, Florida
    Posts
    1,590

    Re: Put/Place Cursor Into UserForm TextBox

    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)

  8. #8
    Join Date
    5th June 2008
    Posts
    14

    Re: Put/Place Cursor Into UserForm TextBox

    Quote Originally Posted by Dave Hawley
    What EXACTLY do you want to do? "did not work" is a helpful as telling the DR you don't feel well.
    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.
    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.
    
    
    Quote Originally Posted by Aaron Blood
    Isolating the simple code to a userform with Textbox1 on page 1 of a multipage control... the code works fine.
    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:
    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.
    
    
    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.

    Excel Video Tutorials / Excel Dashboards Reports


  9. #9
    Join Date
    5th June 2008
    Posts
    14

    Re: Put/Place Cursor Into UserForm TextBox

    Some follow up to this issue. Thinking about this fact
    Quote Originally Posted by Discodrew
    I clicked on page 2, then clicked back to page 1 immediately, the cursor did go inside the textbox1.
    so 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 follows
    VB:
     '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 
    
    
    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. voila

    Excel Video Tutorials / Excel Dashboards Reports


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Possible Answers

  1. Replies: 6
    Last Post: August 7th, 2008, 05:35
  2. Set Focus of Cursor in TextBox On UserForm Show
    By akphidelt in forum EXCEL HELP
    Replies: 4
    Last Post: May 18th, 2007, 18:01
  3. Copy Textbox Text When Cursor Moved From Textbox
    By senarumugam2003 in forum EXCEL HELP
    Replies: 5
    Last Post: February 7th, 2007, 21:14
  4. Place Cursor in Cell Text
    By alienscript in forum EXCEL HELP
    Replies: 1
    Last Post: September 5th, 2006, 19:23
  5. Place UserForm Textbox Data Into Cells On A Sheet
    By minitman in forum EXCEL HELP
    Replies: 10
    Last Post: January 12th, 2006, 23:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
porno