Change Text in TextBox with VBA

G

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
 
M

missinglinq via AccessMonster.com

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
 
M

Marshall Barton

Paul said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top