Prevent spaces in e-mail address fields

B

BruceG

How does one prevent spaces from being entered in an e-mail address field, or if a space is inserted can it automatically be removed?

Regards,
Bruce
 
D

Douglas J. Steele

Assuming you're using Access 2000 or newer, you can use the Replace function
to remove the blanks:

Replace(EmailAddress, " ", "")

Put this in the AfterUpdate event of the text box.

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)


BruceG said:
How does one prevent spaces from being entered in an e-mail address field,
or if a space is inserted can it automatically be removed?
 
B

BruceG

Douglas,

I am using Access 2000, but I don't know where the "AfterUpdate event of the text box" is. I am a newbie.

Thanks,
Bruce
 
D

Douglas J. Steele

I'm assuming you're using a form for input. Go the module associated with
your form, select the text box in the left-hand combobox and "AfterUpdate"
in the right-hand combobox. That'll generate a code shell like:

Private Sub Text1_AfterUpdate()

End Sub

(where Text1 will be replaced with whatever the control is actually called.)

Type

Me.Text1 = Replace(Me.Text1, " ", "")

between those two lines:

Private Sub Text1_AfterUpdate()

Me.Text1 = Replace(Me.Text1, " ", "")

End Sub

If you're not using a form, (and you should be!), then there's no way to do
it automatically. You could run an Update query against the table to convert
all the spaces to nothing.


--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)


BruceG said:
Douglas,

I am using Access 2000, but I don't know where the "AfterUpdate event of
the text box" is. I am a newbie.
 
B

BruceG

Thanks, this solution works; however, if I don't enter anything into the field I get a Null error. Below is what the module looks like:

Option Compare Database

Private Sub E_mail1_AfterUpdate()

Me.E_mail1 = Replace(Me.E_mail1, " ", "")

End Sub

Private Sub E_mail2_AfterUpdate()

Me.E_mail2 = Replace(Me.E_mail2, " ", "")

End Sub

Is there any way that I can prevent the error message if I leave the field blank?

Bruce
 
D

Douglas J. Steele

Private Sub E_mail1_AfterUpdate()

If IsNull(Me.E_mail1) = False Then
Me.E_mail1 = Replace(Me.E_mail1, " ", "")
End If

End Sub


--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)


BruceG said:
Thanks, this solution works; however, if I don't enter anything into the
field I get a Null error. Below is what the module looks like:
 
K

kerrpmb

There really is no spaces in an e-mail address field, it generally does not
go through. I know when i am getting in touch with apple's investor
relations on a Microsoft Windows copy operating system that AOL 9.1 puts a _
in the space in between investor and relations. Thank you.
 
A

Arvin Meyer [MVP]

You can remove spaces in an email by saving this in a standard module, and
calling it from the afterupdate event of a text box:

Public Function RemoveSpaces(strIn As String) As String
Dim i As Integer
Dim strOut As String
Dim c As String
strOut = ""
If ((Not IsNull(strIn)) And (strIn <> "")) Then
For i = 1 To Len(strIn)
c = Mid(strIn, i, 1)
If (InStr(1, " ", c) = 0) Then
strOut = strOut + c
End If
Next i
End If
RemoveSpaces = strOut
End Function

And call it like:

Sub txtEmail_AfterUpdate()
Me.txtEmail = RemoveSpaces(Me.txtEmail)
End Sub
 
D

Damiana de Lima

kerrpmb said:
There really is no spaces in an e-mail address field, it generally does
not
go through. I know when i am getting in touch with apple's investor
relations on a Microsoft Windows copy operating system that AOL 9.1 puts a
_
in the space in between investor and relations. Thank you.
 
Top