Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / June 2007

Tip: Looking for answers? Try searching our database.

Check Sum routine

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RobUCSD - 01 Jun 2007 23:22 GMT
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
******************************************************************************************************
ruralguy - 02 Jun 2007 00:16 GMT
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
>******************************************************************************************************

Signature

HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

RobUCSD - 02 Jun 2007 00:45 GMT
It's working now, thanks for your help. Have a great weekend, Rob

>I couldn't test it but give this code a try:
>
[quoted text clipped - 33 lines]
>>End Sub
>>******************************************************************************************************
ruralguy - 02 Jun 2007 03:44 GMT
You are welcome.  Glad I could help.

>It's working now, thanks for your help. Have a great weekend, Rob
>
[quoted text clipped - 3 lines]
>>>End Sub
>>>******************************************************************************************************

Signature

HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.