Thread: Canadian SIN
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jake Marx[_3_] Jake Marx[_3_] is offline
external usenet poster
 
Posts: 860
Default Canadian SIN

Hi Dennis,

Dennis wrote:
On a Useform I have a textbox where the user must enter a
Social Insurance Number (Canadian).

I would like to verify if the number entered is valid.
Someone gave me the following code:



<code snipped

However, Excel doesn't seem to like it. It returns an
error message on

CodeNumber = Del(CodeNumber, 4, 1)


Not sure what that code is attempting to do. There is no Del function in
VBA, so an error will occur. Maybe there was a custom function named Del
that was supposed to included with the code?

Here's some code that I came up with that might do what you're looking for:

Public Function gbVerifySIN(rsSIN As String) _
As Boolean
Dim sNums As String
Dim nChar As Integer
Dim nNum As Integer
Dim sNum As String
Dim nTot As Integer

If rsSIN Like "###-###-###" Then
sNums = Replace$(rsSIN, "-", "")
For nChar = 1 To 8
If nChar Mod 2 = 0 Then
sNum = CStr(CInt(Mid$(sNums, _
nChar, 1)) * 2)
If Len(sNum) = 1 Then
nTot = nTot + CInt(sNum)
Else
nTot = nTot + CInt(Left$(sNum, 1)) + _
CInt(Mid$(sNum, 2))
End If
Else
sNum = Mid$(sNums, nChar, 1)
nTot = nTot + CInt(sNum)
End If
Next nChar
gbVerifySIN = ((10 - nTot Mod 10) = _
CInt(Right$(sNums, 1)))
End If
End Function

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]