text vs value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to distinguish between the properties of value vs text for a
textbox control and am a little confused. I read the help on it, but still
am a little confused. I typically use the value property in access, but am
having trouble with null values with the value property. I believe with the
text property, I use to add the & "" to the end and it appends the empty
string value to the result of a null. I just need a few decent explanations
and/or senarios on why and when to use value vs text for a textbox
control....

Thanks,
Jason
 
Hi,
the .Text property will only hold the actual value of a textbox control when
it is in focus veras the .Value property is the default property of a control
and it holds the last saved value of the control at any time. The only way to
update the .Text property would be to move the focus from the control and
then back...or force a save while being within the control. You should
probably always use the default .Value property for these reasons, however
there is a difference between a NULL value and an empty string value. When
checking controls you need to check the 'value' of the control for both. The
following expressions will ALL work for checking both:

If IsNull(Me.YourControl) or Me.YourControl = "" Then
....

OR

If Len(Me.YourControl & vbNullString) = 0 Then
....

OR

If Nz(Me.YourControl,"") = "" Then
....

HTH
Good luck
 
In Access, the Text property applies only when the control has focus. As the
user types into a control, .Text returns what is currently there. The
control's Value is not updated until validation begins.

For example, if you have a text box bound to a Date/Time field, and the user
is entering a date, they may have typed:
1/1/
The date is incomplete. It could not possibly become the Value of the
control, because it is not a valid date. However it could the the Text of
the control at that point.

For validation of a control, you normally use its BeforeUpdate event. The
Value property is up to date when this event fires, so that's what you test.
You very rarely use the Text of the control. You might do so if you are
working with the control's Change event (after every keystroke), or if you
want to see whether the user typed a particular character as in this
article:
Enter a value as a percent
at:
http://allenbrowne.com/casu-16.html

You question suggests you are struggling with nulls. You can test if text
box Text1 is Null with:
If IsNull(Me.Text1) Then
If you want to test whether is it Null or a zero-length string, you can use:
If Me.Text1 & "" = "" Then
I suggest you think carefully before allowing zero-length strings into your
table. To the user, there is no visible difference between a Null and a ZLS,
so the interface is confusing. Worse, the database itself is probably
inconsistent, the querying is inefficent, and the coding and queries are
error-prone. There are *very* few cases where a ZLS is desirable data.

If Nulls are giving you headaches, this article identifies just half a dozen
cases that will get you around most of the issues:
Common errors with Null
at:
http://allenbrowne.com/casu-12.html
 
Back
Top