checking a textbox for spaces...

  • Thread starter Thread starter Brad Pears
  • Start date Start date
B

Brad Pears

How do you check for spaces in a text box? I can check for isnull(txtbox)
but what if the user presses space bar a few times? Also len(txtbox) = 0
does not work because spaces are something! What do you check for then?

Thanks,

Brad
 
To eliminate any starting and closing spaces, use Trim e.g.
IsNull(Trim(txtBox)) should yield True if the user has entered nothing but
spaces.

Hope This Helps
Gerald Stanley MCSD
 
Hi Brad

Do you want to allow spaces within the data entered - for example "Brad
Pears"?

If so, then use the Trim function to remove all leading and trailing spaces:
If Len(Trim(txtbox) & "") = 0 then ...

The & "" looks after the case where txtbox is Null, because in that case
Trim would return Null and Len(Null) is Null, not zero.

If you want to disallow spaces anywhere in the string, then use InStr:
If IsNull(txtbox) Or InStr(txtbox, " ") <> 0 Then ...
 
Back
Top