I am working on a project to look in a couple of fields for 16 consecutive numbers, I am masking credit card numbers I can get this to work with the following code, for fields where it begins or ends with 16 consecutive numbers. The problem I am having is a field with alpha on either side, or a numeric string longer then 16 digits. I guess what I need is something to look for 16 digits in a field, and replace place 7-12 with *’s. VBA doesn’t like wild cards in any of the string functions. Any help would be great.
Andrew
Andrew
Code:
Public Function fnMaskCCNumbers(Item As String, fld As String)
Dim str As String
Dim rst As Recordset
Dim str1 As String
Dim str2 As String
Dim strlen As Integer
Set rst = CurrentDb.OpenRecordset(Item, dbOpenDynaset)
rst.MoveFirst
Do Until rst.EOF = True
If rst(fld) Like "*################" Or rst(fld) Like "################*" Or rst(fld) Like "*################" Then
str = rst(fld)
'starts with CC rst(fld) Like "################*"
If IsNumeric(Left(str, 16)) = True Then
str1 = Left(str, 6) & Chr(42) & Chr(42) & Chr(42) & Chr(42) & Chr(42) & Chr(42) & Mid(str, 12, 37)
Debug.Print str1
rst.Edit
rst(fld) = str1
rst.Update
'ends with CC rst(fld) Like "*################"
ElseIf IsNumeric(Right(str, 16)) = True Then
strlen = Len(str)
str2 = Left(str, (strlen - 10)) & Chr(42) & Chr(42) & Chr(42) & Chr(42) & Chr(42) & Chr(42) & Right(str, 4)
Debug.Print str2
rst.Edit
rst(fld) = str2
rst.Update
End If
End If
rst.MoveNext
Loop
rst.Close
End Function
Comment