1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: vb macro, textbox, how to basics.

Discussion in 'Business Applications' started by balloon_tom, Jan 21, 2006.

Thread Status:
Not open for further replies.
  1. balloon_tom

    balloon_tom Thread Starter

    Jan 4, 2006
    Well folks, I told you I'd be back when I started the VB!
    2 questions that should be pretty basic.
    Scenario: This is an Excel macro. I have a userform 'frmSearch' containing 7 single line text boxes 'txtSearchABC, 'txtSearchDEF', etc. for data input and a couple of command buttons.

    1) I want to clear the text from the text boxes. Right now I use:

    I think I should be able to use a for each loop like:
    for each ??? in ???

    but I don't know the exact syntax. Please make suggestions!

    2) Currently, when I enter a text box that already has data in it, new data is appended to the old. What I would like to do is enter a text box and have the '_enter()' highlight the existing text in blue such that new text would replace the old by default, or I could at my option, move the cursor within the text to modify the existing text. I don't know how to select the existing text and highlight it.

    I hope this makes some sense and I'm sure you'll have the answers.
  2. balloon_tom

    balloon_tom Thread Starter

    Jan 4, 2006
    OK, Problem 2 is solved. This is where I wanted to enter a text box with the text highlighted. An extensive web search suggested methods using selStart ,selLength etc. but non of those worked. Then there was the method using SendKeys "{HOME}" and that didn't work. Finally, after much experimentation and frustration, I tried:

    in Sub txtBox1_enter()

    SendKeys "^{A}"

    and that did it.

    I still need help with the 'For Each' loop, though.
  3. OBP

    OBP Temporarily Banned

    Mar 8, 2005
    tom, try this, I know it can be used to set the controls of the textbox but I am not sure about the contents
    for each ctl in userform1.controls
    if typename(ctl) = "TextBox" then
    ctl.text.value = ""
    end if
    next ctl
    put your user form name in place of userform1
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/435953

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice