PC Review


Reply
Thread Tools Rate Thread

Check for spaces

 
 
alex
Guest
Posts: n/a
 
      9th Jul 2010
Check for spaces

Hi,

Using Access ’03…

I have some code behind a Form that checks the value of several
unbound text/combo boxes.

If the control = Null or “” then the code doesn’t run (pretty simple).

My problem, however, is that my code will run (allow) when a user
simply enters a space(s) (hitting spacebar once or multiple times).

How can I avoid this?

The code I referenced is mostly SQL code, so when I DIM the variables,
I usually set them to zls to avoid invalid use of null errors; e.g.,:
nz(myUnboundControl,””). But I need the code to be smart enough to
ignore nulls, zls, or spaces.

Any Thoughts?

Thanks,
alex
 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      9th Jul 2010
Try:

If Len(Trim(Forms![NameOfForm]![NameOfControl] & vbNullString)) > 0 Then

' Run your code

End If

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
Co-author: Access 2010 Solutions, published by Wiley
(no e-mails, please!)

"alex" <(E-Mail Removed)> wrote in message
news:eb0b4d0d-080b-4f94-b851-(E-Mail Removed)...
Check for spaces

Hi,

Using Access ’03…

I have some code behind a Form that checks the value of several
unbound text/combo boxes.

If the control = Null or “” then the code doesn’t run (pretty simple).

My problem, however, is that my code will run (allow) when a user
simply enters a space(s) (hitting spacebar once or multiple times).

How can I avoid this?

The code I referenced is mostly SQL code, so when I DIM the variables,
I usually set them to zls to avoid invalid use of null errors; e.g.,:
nz(myUnboundControl,””). But I need the code to be smart enough to
ignore nulls, zls, or spaces.

Any Thoughts?

Thanks,
alex


 
Reply With Quote
 
alex
Guest
Posts: n/a
 
      9th Jul 2010
On Jul 9, 9:17*am, "Douglas J. Steele"
<NOSPAM_djsteele@NOSPAM_gmail.com> wrote:
> Try:
>
> If Len(Trim(Forms![NameOfForm]![NameOfControl] & vbNullString)) > 0 Then
>
> ' Run your code
>
> End If
>
> --
> Doug Steele, Microsoft Access MVPhttp://www.AccessMVP.com/DJSteele
> Co-author: Access 2010 Solutions, published by Wiley
> (no e-mails, please!)
>
> "alex" <sql_...@yahoo.com> wrote in message
>
> news:eb0b4d0d-080b-4f94-b851-(E-Mail Removed)...
> Check for spaces
>
> Hi,
>
> Using Access ’03…
>
> I have some code behind a Form that checks the value of several
> unbound text/combo boxes.
>
> If the control = Null or “” then the code doesn’t run (pretty simple).
>
> My problem, however, is that my code will run (allow) when a user
> simply enters a space(s) (hitting spacebar once or multiple times).
>
> How can I avoid this?
>
> The code I referenced is mostly SQL code, so when I DIM the variables,
> I usually set them to zls to avoid invalid use of null errors; e.g.,:
> nz(myUnboundControl,””). *But I need the code to be smart enough to
> ignore nulls, zls, or spaces.
>
> Any Thoughts?
>
> Thanks,
> alex


Doug, that worked perfectly!
I don't really understand the code, however.

Why will an IIF(test for "") function ignore multiple spaces (just
spaces);
and
If (test for "")
End If
will not?
Seems strange.
alex
 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      9th Jul 2010
What was the actual code you were using before?

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
Co-author: Access 2010 Solutions, published by Wiley
(no e-mails, please!)

"alex" <(E-Mail Removed)> wrote in message
news:15b00f65-3082-40ca-882d-(E-Mail Removed)...
On Jul 9, 9:17 am, "Douglas J. Steele"
<NOSPAM_djsteele@NOSPAM_gmail.com> wrote:
> Try:
>
> If Len(Trim(Forms![NameOfForm]![NameOfControl] & vbNullString)) > 0 Then
>
> ' Run your code
>
> End If
>


Doug, that worked perfectly!
I don't really understand the code, however.

Why will an IIF(test for "") function ignore multiple spaces (just
spaces);
and
If (test for "")
End If
will not?
Seems strange.
alex


 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      9th Jul 2010
If Len(Trim(Forms![NameOfForm]![NameOfControl] & vbNullString)) > 0 THEN

Break it down into its parts starting from the center expression and working out.

---Forms![NameOfForm]![NameOfControl] & vbNullString
Concatenates (adds) a zero-length string to whatever is in the control turning
nulls into ""
"" into ""
" " into " "
"Abcdef" into "Abcdef"

-- TRIM ( ... ) removes any leading or trailing spaces, so the first three
examples above all become ""

-- Len( ... ) determines the character length. "" is zero characters long. If
you failed to trim the expression, then example number 3 above it would be 4
characters long (space is a character - it is just not visible to the human
eye other than when there are characters surrounding the white space.

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

Douglas J. Steele wrote:
> What was the actual code you were using before?
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Spaces Between Check Boxes Amber Microsoft Access Reports 2 26th Mar 2008 09:36 PM
How to check subject line and add spaces in it =?Utf-8?B?UlM=?= Microsoft Outlook Discussion 1 29th Jun 2007 08:50 PM
Grammer check option for two spaces after a colon =?Utf-8?B?SmVkaSBIb3Ro?= Microsoft Word Document Management 1 30th Apr 2005 01:10 AM
how do i check a field for spaces in a query? =?Utf-8?B?dHdvY2Fuc2FtMQ==?= Microsoft Access 2 11th Apr 2005 05:09 PM
How do I get grammar check to recognize extra spaces between words =?Utf-8?B?RUoncyBtb20=?= Microsoft Word Document Management 2 4th Mar 2005 10:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:43 AM.