Public Function getSpecialID(firstStr As String, middleStr As Variant, lastStr As String) As String
[COLOR=Green]'-------------------------------------------------------------------------
' A Function that will take in First Name, Middle Name and Last Name
' returns a Specially designed UserID.
'
' Input : First Name, Middle Name and Last Name
' Output : A UserID
' Example :
' ? getSpecialID("Mary", "Q", "Shortname")
' USKMMQSHORTN
' ? getSpecialID("John", "", "Hasareallyreallylonglastname")
' USKMJHASAREA
[/COLOR][COLOR=Green]' ? getSpecialID("John", "", "Has[U][B]another[/B][/U]longlastname")
' USKM1JHASARE[/COLOR]
[COLOR=Green]'--------------------------------------------------------------------------[/COLOR]
Dim retStr As String, ctr As Long
ctr = 0
retStr = "USKM" & Left(firstStr, 1)
If Len(middleStr & vbNullString) <> 0 Then retStr = retStr & Left(middleStr, 1)
retStr = retStr & Left(lastStr, 12 - Len(retStr))
retStr = UCase(retStr)
While DCount("*", "[COLOR=Blue][B]theTableName[/B][/COLOR]", "[B][COLOR=Blue]fieldName[/COLOR][/B] = '" & retStr & "'") > 0
[COLOR=Green]'How you wish to change the name?
'Maybe:[/COLOR]
ctr = ctr + 1
Wend
If ctr <> 0 Then retStr = "USKM" & ctr & Mid(retStr, 5)
getSpecialID = Left(retStr, 12)
End Function