I am trying to validate entry of a form field using the following VBA. This works very well. My problem is this Access app creates a variety of XML data files, and I don’t want certain characters within that xml….namely soft-returns (Shift+Enter). I believe that the Chr for this is Chr(11), but I don’t think I can just add , Chr(11)) to the end of the array below and this will work…how can I use Chr(#) in link manner?
Dim i, j As Integer
dim myField as variant
varNo = Array("\", "/", ":", "*", "?", """", "<", ">", "|")
If IsNull(Me.FieldValue) = False Then
myField = Me.FieldValue
For i = 0 To UBound(varNo)
j = InStr(1, myField , varNo(i))
If j > 0 Then
MsgBox "Cannot use character:" & Chr(13) & Chr(10) & Chr(13)
& Chr(10) & varNo(i), vbCritical, " Illegal Character"
Exit Sub
Exit For
End If
Next
End If
again the above works great for those things in the array, but I would like to include Chr() as well.
You can build your array with an empty string as the new last element, then change the value of the last element to
Chr(11).Actually, I’m unsure why that should be necessary. This works for me …
Based on the comments, I think it will be useful to confirm the text you’re evaluating actually contains the characters you expect. Feed the text to this procedure and examine its output in the Immediate window.