Change Text in TextBox with VBA

Discussion in 'Microsoft Access Form Coding' started by Guest, Dec 18, 2006.

  1. Guest

    Guest Guest

    I have a TextBox on a form. At times, I want my VBA code to copy a string
    into this TextBox. So far, the only way I have been able to do this is by
    temporarily setting focus to this TextBox. My code looks basically like this:

    MyTextBox.SetFocus
    MyTextBox.Text = MyStringVariable
    MyOtherControl.SetFocus

    This works, but my problem is that I don't want this TextBox to be visible
    and I do not want it to be a TabStop. Whenever I set the TextBox Visible and
    Tabstop properties to "No", my code no longer works. I think this is because
    focus can no longer be set to the TextBox.

    Is there another way that I can manipulate the text in a TextBox without
    setting focus to it? Or, is there a way that I can hide this TextBox from my
    users without setting the Visible and Tabstop properties to "No"?

    Thanks,
    Paul
    --
    Paul Kraemer
     
    Guest, Dec 18, 2006
    #1
    1. Advertisements

  2. Guest

    HRE Guest

    Try useing MyTextBox.Value = MyStringVariable instead.

    Paul Kraemer wrote:
    > I have a TextBox on a form. At times, I want my VBA code to copy a string
    > into this TextBox. So far, the only way I have been able to do this is by
    > temporarily setting focus to this TextBox. My code looks basically like this:
    >
    > MyTextBox.SetFocus
    > MyTextBox.Text = MyStringVariable
    > MyOtherControl.SetFocus
    >
    > This works, but my problem is that I don't want this TextBox to be visible
    > and I do not want it to be a TabStop. Whenever I set the TextBox Visible and
    > Tabstop properties to "No", my code no longer works. I think this is because
    > focus can no longer be set to the TextBox.
    >
    > Is there another way that I can manipulate the text in a TextBox without
    > setting focus to it? Or, is there a way that I can hide this TextBox from my
    > users without setting the Visible and Tabstop properties to "No"?
    >
    > Thanks,
    > Paul
    > --
    > Paul Kraemer
     
    HRE, Dec 18, 2006
    #2
    1. Advertisements

  3. HRE's correct, MyTextBox.Text requires that the control has focus, MyTextBox.
    Value doesn't! I use the latter all the time so I don't have to worry about
    focus.

    --
    There's ALWAYS more than one way to skin a cat!

    Answers/posts based on Access 2000

    Message posted via AccessMonster.com
    http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200612/1
     
    missinglinq via AccessMonster.com, Dec 18, 2006
    #3
  4. Paul Kraemer wrote:

    >I have a TextBox on a form. At times, I want my VBA code to copy a string
    >into this TextBox. So far, the only way I have been able to do this is by
    >temporarily setting focus to this TextBox. My code looks basically like this:
    >
    >MyTextBox.SetFocus
    >MyTextBox.Text = MyStringVariable
    >MyOtherControl.SetFocus
    >
    >This works, but my problem is that I don't want this TextBox to be visible
    >and I do not want it to be a TabStop. Whenever I set the TextBox Visible and
    >Tabstop properties to "No", my code no longer works. I think this is because
    >focus can no longer be set to the TextBox.
    >
    >Is there another way that I can manipulate the text in a TextBox without
    >setting focus to it? Or, is there a way that I can hide this TextBox from my
    >users without setting the Visible and Tabstop properties to "No"?



    I'll try to explain why you should not use the Text
    property. Unlike VB, Access uses the Value property
    instead. For Access text and combo box controls, the Text
    property is only useful in fairly limited situations because
    it contains a user's input at any point until the entered
    string is completed (by using Tab, Enter or mouse). When
    comitted, the entered text is then evaluated (converted to
    binary, trimmed or whatever) and stored in the Value
    property.

    Note that the Text property doesn't even exist for other
    types of controls.

    --
    Marsh
    MVP [MS Access]
     
    Marshall Barton, Dec 18, 2006
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Silvester

    limiting lines per textbox and spill it over to 2nd textbox

    Silvester, Jan 12, 2004, in forum: Microsoft Access Form Coding
    Replies:
    0
    Views:
    164
    Silvester
    Jan 12, 2004
  2. Silvester

    limiting lines per textbox and spill it over to 2nd textbox

    Silvester, Jan 14, 2004, in forum: Microsoft Access Form Coding
    Replies:
    0
    Views:
    181
    Silvester
    Jan 14, 2004
  3. Silvester

    limiting lines per textbox and spill it over to 2nd textbox

    Silvester, Jan 14, 2004, in forum: Microsoft Access Form Coding
    Replies:
    0
    Views:
    155
    Silvester
    Jan 14, 2004
  4. leon

    copy text in textbox to another textbox on click

    leon, Mar 30, 2005, in forum: Microsoft Access Form Coding
    Replies:
    3
    Views:
    1,171
    Dan Artuso
    Mar 30, 2005
  5. CompleteNewb

    Change textbox color based on matching value in different textbox

    CompleteNewb, Nov 15, 2007, in forum: Microsoft Access Form Coding
    Replies:
    4
    Views:
    944
    CompleteNewb
    Nov 16, 2007
Loading...

Share This Page