Best practice data-typing combo/text box contents

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

Guest

Using Office 2003 and Windows XP;

If a text box control on a form contains a string, is it best practice to
use TEXT as in: sData = Me.MyControl.Text

Then, if it contains a value to use VALUE as in: iData = Me.MyControl.Value

Also, what is the best practice for determining if a textbox or a combo
contains a NULL. I've been using a construct like:

If Not IsNull(Me.MyControl.Value) Then iData = Me.MyControl.Value Else iData
= 0

Then I check the contents of iData. Is this the best or accepted practice?

Is there some other better fool proof way to get the contents and absolutely
deal with it without generating an error in the process and identify Null's,
or any other entry type, etc?

Please post a generic function if you have one. Thanks for your input and/or
discussion/advice on this.
 
AFAIK, there is no difference between what's returned for the Text or Value
properties. (plus, to refer to the Text property, the control must have
focus). Value is actually the default property, so it's not really necessary
to include it.

Rather than the If construct you're using, you could use the Nz function,
which is designed specifically for that requirement.

Try something like:

sData = Nz(Me.MyControl.Value, "") or sData = Nz(Me.MyControl, "")

for string values, or

iData = Nz(Me.MyControl.Value, 0) or iData = Nz(Me.MyControl, 0)
 
Thanks much Douglas; I will use NZ from now on; much better than my method.

How about if a control is either hidden or locked?

Can you suggest any shortcuts on returning data from controls in either of
those states? Controls must receive focus to unhide/unlock before data can be
retrieved from them, right?
 
Back
Top