• calculation assistance please (A2K)

    Author
    Topic
    #360917

    Hi,

    In the air freight industry we use an Air Waybill number to ship goods, this consists of 3 numbers or letters then a separator and then 8 numbers. Most airlines these days belong to IATA who have certain rules about the way an air waybill is calculated. A number I have used is 125-58325676, the rules are that a number must always increase by 11 but cannot finish with 7, 8 or 9, when a number ends in 6 it reverts to 0, for example

    125-58325676
    125-58325680
    125-58325691

    etc.

    That’s the easy part over. To test if the number is an IATA issued number you have to divide the first 7 of the last 8 by 7, what’s left over will always be the last number (number 8) for the air waybill, the sum therefore using the first number I gave 58325676 would be

    58 / 7 = 8 (leaves 2) 23 / 7 = 3 (leaves 2) 22 / 7 = 3 (leaves 1) 15 / 7 = 2 (leaves 1) 16 / 7 = 2 (leaves 2) 27 / 7 = 3 (leaves 6) and as you can 6 is the indeed the last number of the air way bill. If any one can help how do I.

    a. In a text box on my form make that calculation, ignoring any 4 preceding numbers or letters or dashes, i.e. 125-

    b. If it doesn’t calculate right because the user input say a 5 at the end instead of a 6 would an ordinary validation rule asking ‘This is not an IATA number do you wish to continue’ YES / NO let them choose if the continue with the wrong number (I actually want them to able to continue by choice because to complicate matters not all airlines are IATA affiliated).

    On a different matter has anybody noticed Woody’s frequent facts about Camels, I am getting a little concerned about life in Chiang Mei or where ever he is hanging out in Thailand.

    TIA

    Steve

    Viewing 0 reply threads
    Author
    Replies
    • #544539

      Here – l implemented your algorithm for you. It’s ugly and would better have been done with a little recursive routine, but I didn’t have enough neurons to spare this morning.

      Call the IsIATAWayBill routine with the full way bill (xxx-yyyyyyyy) and you will get back a TRUE if it is a way bill and false if it’s not.

      Function IsIATAWayBill(strWayBillNumber As String) As Boolean
      Dim strWBN As String
      Dim intCheckDigit As Integer

      If Len(strWayBillNumber) 12 Then
      IsIATAWayBill = False
      Exit Function
      ElseIf Mid(strWayBillNumber, 4, 1) “-” Then
      IsIATAWayBill = False
      Exit Function
      Else
      strWBN = Mid(strWayBillNumber, 5, 7)
      intCheckDigit = ((((((((((Left(strWBN, 2) Mod 7) & Mid(strWBN, 3, 1)) Mod 7) & Mid(strWBN, 4, 1)) Mod 7) & _
      Mid(strWBN, 5, 1)) Mod 7) & Mid(strWBN, 6, 1)) Mod 7) & Right(strWBN, 1)) Mod 7
      If intCheckDigit = Right(strWayBillNumber, 1) Then
      IsIATAWayBill = True
      Else
      IsIATAWayBill = False
      End If
      End If
      End Function

      • #544638

        Thnaks Jordan, a little more help though please. I assume that this should go in the EventProcedure for After update but nothing happens when I put in a false number, I then tried it OnExit with a false number but it just carried on. I am obviously doing something wrong but could you tell me what.

        Thanks

        Steve

        • #544769

          You just need to add a little more code to the function telling Access what to do when Jordan’s code is true, and what to do when it is false. In your case you could simply exit the function when it is true, but, if it’s false, send your msgbox, which will warn the user.

    Viewing 0 reply threads
    Reply To: calculation assistance please (A2K)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: