ctl.Text --vs-- ctl.Value

J

John Keith

For Each ctl In Me.Section(acHeader).Controls
--code--
Next ctl

For an unbound textbox control in the header section of my form...
ctl.Text stores "100" which is what I typed
ctl.Value is null

Why?

What is the difference in these properties?
 
A

Albert D. Kallal

You will very rarely if ever need to use .text in your code.

you'll often see some amateurs write the following code

me.MyTextBox.SetFocus
msgbox "the value is " & me.MytextBox.Text

The problem is with the use of the dot text property, it is only valid and
legal to use while the control has the focus. sometimes it takes some new
developers to access a better time to figure this out, you'll often see
hundreds of lines of code where they want to get, or set the value of a
controlled so we have Williams and billions of set focus commands plastered
all over.

of bout the only time you'll ever use .text is when you're doing some coding
with the on change event of a control (since the text will not have been
written from the text box to the actual "value".

for 99% of all other code, you simply are going to use the .value property.
(and of course the .value property does not need the focus either).

I should point out that the .value property is in fact the default property
of the control, so a lot of us developers actually just leave out the.value
for most of our code....

msgbox "the value is " & me.MyTextbox
 
J

John Keith

I discovered my issue with .text having "100" and .value being null was
caused by interactive debugging.

Still there is a problem, but im starting a seperate thread to ask a new
question :)
 

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