Search a text string entered into text box before update

M

Mollybot

I have created a form which requests information from the user which is
entered into a text box. I cannot apply an input mask because the string
entered can vary considerably however I would like to check that the
characters entered do not include ' , ; @ etc. before the record field is
written.

I understand I need to take the string and search it character by character
and remove each instance of the 'illegal' character from the string. Is
there a function or method that already does this type of thing or do I have
to write it, if the later I need some pointers please. Can I also specifiy
what characters I consider illegal?

Thanks for any help you can offer.
 
A

Allen Browne

Set a Validation Rule of:
Is Null Or Not Like "*[ ,;@]*"

Add whateever other characters are illegal inside the square brackets.
 
M

Mollybot

That was easy! Perhaps I need a lot more access coding before I can say I
am becoming proficient.

Thanks for your prompt repsonse Allen, much appreciated.

Mollybot.

Allen Browne said:
Set a Validation Rule of:
Is Null Or Not Like "*[ ,;@]*"

Add whateever other characters are illegal inside the square brackets.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Mollybot said:
I have created a form which requests information from the user which is
entered into a text box. I cannot apply an input mask because the string
entered can vary considerably however I would like to check that the
characters entered do not include ' , ; @ etc. before the record field is
written.

I understand I need to take the string and search it character by
character
and remove each instance of the 'illegal' character from the string. Is
there a function or method that already does this type of thing or do I
have
to write it, if the later I need some pointers please. Can I also
specifiy
what characters I consider illegal?

Thanks for any help you can offer.
 
C

carlkern(removethis)

Mollybot said:
I have created a form which requests information from the user which is
entered into a text box. I cannot apply an input mask because the string
entered can vary considerably however I would like to check that the
characters entered do not include ' , ; @ etc. before the record field is
written.

Here is a more general use routine In use in all my applications. It uses
the REPLACE function and loops through a list of forbidden charasters and
removes them from the supplied string.

Public Function CleanChars(strToProc, _
Optional ByVal strCharsToStrip As String) As Boolean
'------------------------------------------------------------
'Comments: Strips the specified characters from a string
'Parameters:
' strToProc - The string we want to remove chars from
' strCharsToStrip - The character(s) to remove. Can be more than 1 char
(no space)
' If not specified all special chars (noted below)
' are removed
'Returns: Clean string for all occurences of character
'Created: based on 'Function StripSpecialChars' 4/30/2005 - MFG
'Modified: 10/27/05 CK
'------------------------------------------------------------
Dim strBadChar As String
Dim j As Long
Dim strCleaned As String

On Error GoTo Err_CleanChars
CleanChars = False

If Len(strCharsToStrip) = 0 Then
'default chars to be stripped out, Chr(34)= double quote ("), Chr(39) =
single quote (')
strCharsToStrip = ",&~!@#$%^&*()-;:\|{}[]/" & Chr(34) & Chr(39)
End If

strCleaned = strToProc
For j = 1 To Len(strCharsToStrip)
strBadChar = Left(strCharsToStrip, 1)
If strBadChar <> " " Then strCleaned = Replace(strCleaned, strBadChar, "
")
If Len(strCharsToStrip) - 1 = 0 Then Exit For
strCharsToStrip = Right(strCharsToStrip, Len(strCharsToStrip) - 1)
Next j

strToProc = strCleaned
CleanChars = True

Exit_CleanChars:
Exit Function

Err_CleanChars:
MsgBox Err.Number & ": " & Err.Description
Resume Exit_CleanChars

End Function
 
Top