Check for leading or trailing spaces

  • Thread starter Thread starter mjones
  • Start date Start date
M

mjones

Hi All,

My staff keeps copying and pasting text into form fields from emails
and such with trailing and leading spaces, e.g. on email addresses.
Obviously, this is junk data.

Is there a way to on exit or the like, check for leading and/or
trailing spaces and give an error until they fix it?

Something like -

If Me!EmailP "STARTS OR ENDS WITH A SPACE" Then
MsgBox "Email cannot start or end with a space'"
Cancel = False
End If

Hum, probably not that simple, but one can hope.

Thanks a bunch,

Michele
 
Hi All,

My staff keeps copying and pasting text into form fields from emails
and such with trailing and leading spaces, e.g. on email addresses.
Obviously, this is junk data.

Is there a way to on exit or the like, check for leading and/or
trailing spaces and give an error until they fix it?

Something like -

If Me!EmailP "STARTS OR ENDS WITH A SPACE" Then
MsgBox "Email cannot start or end with a space'"
Cancel = False
End If

Hum, probably not that simple, but one can hope.

Thanks a bunch,

Michele

Access automatically trims trailing blanks.

What I'd suggest is that you simply trim the input silently, without annoying
your users with a message; you can put code into the textbox's AfterUpdate
event (oddly, that is the AFTER update event, not Before):

Private Sub txtEmail_AfterUpdate()
Me!txtEmail = Trim(Me!txtEmail)
End Sub

This will trim both ends.
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 
Access automatically trims trailing blanks.

What I'd suggest is that you simply trim the input silently, without annoying
your users with a message; you can put code into the textbox's AfterUpdate
event (oddly, that is the AFTER update event, not Before):

Private Sub txtEmail_AfterUpdate()
Me!txtEmail = Trim(Me!txtEmail)
End Sub

This will trim both ends.
--

             John W. Vinson [MVP]
 Microsoft's replacements for these newsgroups:
 http://social.msdn.microsoft.com/Forums/en-US/accessdev/
 http://social.answers.microsoft.com/Forums/en-US/addbuz/
 and see alsohttp://www.utteraccess.com

Wonderful! Even better automatic.

John (or anyone), please consider my offer of payment to resolve the
issue in my last post ‘Launching Report from Form Only Shows Report
for First Record’ which turned out to be an issue of two client’s on
the same form. My Invoices and Receipts both have this problem.
 
Back
Top