Determine length of text in unbound textbox.

  • Thread starter Thread starter David G.
  • Start date Start date
D

David G.

Simple form. 2 controls:
1. "Name" is an unbound Text box
2. "Save" is a command button

I disable "Save" on form load.
I sink "Name" OnChange event.

VBA Code:
Name_OnChange()
if Len(me.Name) >0 then
me.Save.enabled=true
else:
me.Save.enabled=false
end if
end sub

Doesn't work. Len(me.Name) always = 0 (zero)


THANKS!
David G.
 
I only used "Name" and "Save" for brevity. the controls are named
"tbxQueryName", and "cmbSave" respectfully.

You cannot name a control "name" this is a reserved word and will lead to
problems (as you have found out).

For a complete listing of reserved words... see:
http://allenbrowne.com/AppIssueBadWord.html

Change the name of your control, avoiding any reserved word, and your code
should work.
THANKS!
David G.
 
Simple form. 2 controls:
1. "Name" is an unbound Text box
2. "Save" is a command button

I disable "Save" on form load.
I sink "Name" OnChange event.

VBA Code:
Name_OnChange()
if Len(me.Name) >0 then
me.Save.enabled=true
else:
me.Save.enabled=false
end if
end sub

Doesn't work. Len(me.Name) always = 0 (zero)

THANKS!
David G.

I'm not sure why you are doing this, but....
Until the entered data is saved, the unbound control has a Text
property, not a Value property, so:

if Len(me.Name.Text) >0 then
 
That's what I needed. THANKS!
I'm not sure why you are doing this, but....
Until the entered data is saved, the unbound control has a Text
property, not a Value property, so:

if Len(me.Name.Text) >0 then
THANKS!
David G.
 
If you are using the change event of the control then check the length of the
text property. The value property won't be set until you exit the control.

Me.Save.Enabled = Len(Me.[Name].Text) > 0

Using Name as the name of a control is a bad idea. The form has a name. So
Me.Name is going to be ambiguous. Are you attempting to refer to the name of
the form or to a control named name? At a minimum, I would change to
control's name to txtName.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
Back
Top