Check Sum routine

  • Thread starter RobUCSD via AccessMonster.com
  • Start date
R

RobUCSD via AccessMonster.com

I want to use the following check sum routine to check for the validity of
newly input medical record numbers (MRN). Problem is that some of the MRN's
have leading zero's so the routine won't work. If I change the MRN field to a
txt field, then it doesn't work at all.

Is there anyway to tell access not to cut off the zero's? Thanks for your
help. Robert

*******************************************************************************************************************

Private Sub MRN_BeforeUpdate(Cancel As Integer)
If Len(MRN) <> 8 Then
MsgBox ("Please enter the full 8 digit Medical Record Number")
Else
If Len(MRN) = 8 Then
Dim MR(8), I, J, K, L, Odd, Even As Integer
For I = 1 To 8
MR(I) = Val(Mid(MRN, I, 1))
Next I
Even = MR(2) + MR(4) + MR(6)
Odd = 2 * (Val(Str(MR(1)) & Str(MR(3)) & Str(MR(5)) & Str(MR(7))))
J = Len(Str(Odd))
For I = 1 To J
K = K + Val(Mid(Str(Odd), I, 1))
Next I
K = K + Even
L = 10 * (Int(K / 10) + 1)
If MR(8) <> L - K Then
If L - K <> 10 Then MsgBox ("That Medical Record Number is NOT
valid!")
End If
Else
MsgBox ("Please enter the full 8 digit Medical Record Number")
End If
End If

End Sub
******************************************************************************************************
 
R

ruralguy via AccessMonster.com

I couldn't test it but give this code a try:

---------------------------------------
If Len(MRN) = 8 Then
Dim MR(8) As String
Dim I As Integer, J As Integer, K As Integer, L As Integer
Dim Odd As Integer, Even As Integer
'-- Put each digit into a separate slot in an array
For I = 1 To 8
MR(I) = Mid(MRN, I, 1)
Next I
Even = Val(MR(2)) + Val(MR(4)) + Val(MR(6))
Odd = 2 * Val(MR(1) & MR(3) & MR(5) & MR(7))
J = Len(Str(Odd))
For I = 1 To J
K = K + Val(Mid(Str(Odd), I, 1))
Next I
K = K + Even
L = 10 * (Int(K / 10) + 1)
If Val(MR(8)) <> L - K Then
If L - K <> 10 Then
MsgBox ("That Medical Record Number is NOT valid! ")
End If
End If
End If
-------------------------------------------------

You can not have leading zeros in a number, only a string. Change your field
to a text field and insert the code I supplied and see if that works for you.
When there is a failure, you may wish to set Cancel = True to hold the focus
in the current control.
 
R

RobUCSD via AccessMonster.com

It's working now, thanks for your help. Have a great weekend, Rob
I couldn't test it but give this code a try:

---------------------------------------
If Len(MRN) = 8 Then
Dim MR(8) As String
Dim I As Integer, J As Integer, K As Integer, L As Integer
Dim Odd As Integer, Even As Integer
'-- Put each digit into a separate slot in an array
For I = 1 To 8
MR(I) = Mid(MRN, I, 1)
Next I
Even = Val(MR(2)) + Val(MR(4)) + Val(MR(6))
Odd = 2 * Val(MR(1) & MR(3) & MR(5) & MR(7))
J = Len(Str(Odd))
For I = 1 To J
K = K + Val(Mid(Str(Odd), I, 1))
Next I
K = K + Even
L = 10 * (Int(K / 10) + 1)
If Val(MR(8)) <> L - K Then
If L - K <> 10 Then
MsgBox ("That Medical Record Number is NOT valid! ")
End If
End If
End If
-------------------------------------------------

You can not have leading zeros in a number, only a string. Change your field
to a text field and insert the code I supplied and see if that works for you.
When there is a failure, you may wish to set Cancel = True to hold the focus
in the current control.
I want to use the following check sum routine to check for the validity of
newly input medical record numbers (MRN). Problem is that some of the MRN's
[quoted text clipped - 34 lines]
End Sub
******************************************************************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top