Invalid / bad characters (1 Viewer)

BWP

Registered User.
Local time
Today, 02:07
Joined
Jan 31, 2018
Messages
17
Hi All

Is there a way to go through an entire table and look through a field (either using VBA or query) to simply say something like:
Code:
"If [FieldName] has bad characters, "Yes","")

Then once established these are "bad rows of data" - a separate query to update/replace/remove those records (but i guess i'm talking about a lot of records here (i hope) - so i could just go through each one manually once the records are identified...?

Thanks in advance
 

isladogs

MVP / VIP
Local time
Today, 02:07
Joined
Jan 14, 2017
Messages
18,216
What do you mean by bad characters in this context?
 

Minty

AWF VIP
Local time
Today, 02:07
Joined
Jul 26, 2013
Messages
10,371
You can use a function to replace "Special Characters" in a field.

Paste this into module - it should be self-explanatory;
Code:
Public Function fStripIllegal(strCheck As String, Optional strReplaceWith As String = "") As String

    On Error GoTo StripIllErr
    'illegal file name characters included in default string are    ? [ ] /  = + < > :; * " , '   1

    Dim intI             As Integer
    Dim intPassedString  As Integer
    Dim intCheckString   As Integer
    Dim strChar          As String
    Dim strIllegalChars  As String
    Dim intReplaceLen    As Integer

    If IsNull(strCheck) Then Exit Function

    strIllegalChars = "?[]/=+<>:;,*" & Chr(34) & Chr(39) & Chr(13) & Chr(10)        'add/remove characters you need removed to this string

    intPassedString = Len(strCheck)
    intCheckString = Len(strIllegalChars)

    intReplaceLen = Len(strReplaceWith)

    If intReplaceLen > 0 Then        'a character has been entered to use as the replacement character

        If intReplaceLen = 1 Then        'check the character itself isn't an illegal character

            If InStr(strIllegalChars, strReplaceWith) > 0 Then
                MsgBox "You can't replace an illegal character with another illegal character", _
                       vbOKOnly + vbExclamation, "Invalid Character"
                fStripIllegal = strCheck
                Exit Function
            End If

        Else        'only one replacement character allowed

            MsgBox "Only one character is allowed as a replacement character", _
                   vbOKOnly + vbExclamation, "Invalid Replacement String"
            fStripIllegal = strCheck
            Exit Function

        End If
    End If

    If intPassedString < intCheckString Then

        For intI = 1 To intCheckString
            strChar = Mid(strIllegalChars, intI, 1)
            If InStr(strCheck, strChar) > 0 Then
                strCheck = Replace(strCheck, strChar, strReplaceWith)
            End If
        Next intI

    Else

        For intI = 1 To intPassedString
            strChar = Mid(strIllegalChars, intI, 1)
            If InStr(strCheck, strChar) > 0 Then
                strCheck = Replace(strCheck, strChar, strReplaceWith)
            End If
        Next intI

    End If

    fStripIllegal = Trim(strCheck)

StripIllErrExit:
    Exit Function

StripIllErr:
    MsgBox "The following error occured: " & Err.Number & vbCrLf _
           & Err.Description, vbOKOnly + vbExclamation, "Unexpected Error"

    fStripIllegal = strCheck

    Resume StripIllErrExit

End Function
 

BWP

Registered User.
Local time
Today, 02:07
Joined
Jan 31, 2018
Messages
17
What do you mean by bad characters in this context?

This is about "any bad/illegal" characters (i'm not sure what these are). In context - the reason for asking - is during import from legacy system (memo data type field (more like long text field)) - there was some kind of symbol in the text looked like a diagonal arrow pointing top right up. This was causing me massive issues trying to get data from Access to SharePoint - basically failed - and if anyone knows how painful getting data into SP is - it just just time.
 

Users who are viewing this thread

Top Bottom