Results 1 to 8 of 8
  1. #1
    LarryN is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2014
    Posts
    4

    Converting Excel check digit formula to Access

    I am calculating the check digit for a 13 digit number in Excel and I need to be able to do it in Access. Any help will be greatly appreciated,


    My Excel formula; =1&E1&MOD(-SUM(MID(1&E1&0,{1,3,5,7,9,11,13;2,4,6,8,10,12,14}, 1)*{3;1}),10) -- cell E1 holds the base 12 digit number.
    My attempt to convert to Access; =1 & [txtBase] & [-SUM(MID("1" & [txtBase] &0,{1,3,5,7,9,11,13;2,4,6,8,10,12,14},1)*{3;1}) mod 10] -- txtBase holds the base 12 digit number

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I have no idea what a 'check digit' is. Please explain this in plain Engish.

    It is possible to invoke and run Excel functions within VBA so you don't have to figure out a VBA substitute. I tested this with matrix multiplication. I found that the results weren't exactly the same between the 3 (Excel formula in spreadsheet cell, VBA invoking Excel, VBA substitute) but close enough.

    http://bytes.com/topic/access/insigh...nctions-access
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    LarryN is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2014
    Posts
    4
    Below is a very good description from Wikipedia. A check digit in this case is used to verify a GTIN (Global Trade Identification Number) which is like a UPC code on products you buy in the store. A UPC code with check digit is 12 digits where a GTIN with check digit is 14 digits.

    A check digit is a form of redundancy check used for error detection on identification numbers (e.g. bank account numbers) which have been input manually. It is analogous to a binary parity bit used to check for errors in computer-generated data.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Did you mean to reference a URL in post?

    Did you look into invoking Excel functions?

    Now explain the algorithm for the calculation you want (i.e., (a * b / c) - 15) or whatever. If you did this by pencil and paper, what steps would you follow? In a word, pseudocode.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    It would have been nice to have a before and after example of a GTIN, but with what you provided and searching the web, I cobbled a function together.
    In this function, the GTIN must be a string.

    The function:
    Code:
    Public Function CalcGTIN(pGTIN As String) As String
        'http://www.gs1sy.org/GS1System/id_keys/CheckDigit.htm
    
        'the number to multiply by
        Const N As String = "131313131313"
        Const NumOfDigits As Integer = 12
    
        Dim i As Integer  'counter
        Dim ChkDigit As Long   '
        Dim txtBase As String  '
        Dim x As Long
    
        'set default return value
        CalcGTIN = "00000000000000"
    
        txtBase = Trim(pGTIN)
    
        If Len(txtBase) = NumOfDigits Then
            For i = 1 To NumOfDigits
                x = x + (Mid(txtBase, i, 1) * Mid(N, i, 1))
            Next
    
            ' next bigger number and subtract ChkNum
            ChkDigit = (x + (10 - (x Mod 10))) - x
    
            'return
            CalcGTIN = "1" & txtBase & ChkDigit
        End If
    
    End Function
    Call it using:
    Code:
    Sub TestGTIN()
        Dim sWithCheckdigit As String
        Dim TradingProcessNum As String
    
        TradingProcessNum = "629104150021"
    
        sWithCheckdigit = CalcGTIN(TradingProcessNum)
    
    
    'this should be one line
        MsgBox "Original = " & TradingprocessNum & " - " & Len(TradingProcessNum) & " characters " & vbNewLine & vbNewLine & "GTIN = " & sWithCheckdigit & " - " & Len(sWithCheckdigit) & " characters "
    
    End Sub

  6. #6
    LarryN is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2014
    Posts
    4
    Thank you I appreciate what you have done. This will work, I was hoping for something like what I am using for Excel that I could use in the Expression Builder.

  7. #7
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    If ssnafu's function does what you want and you make it a public function you should be able to call it anywhere in your code/queries you want similar to the built in functions.

  8. #8
    LarryN is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2014
    Posts
    4
    That is what I plan on doing, thank you.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 41
    Last Post: 05-29-2015, 02:58 PM
  2. Converting this formula to an access database
    By prabha_friend in forum Queries
    Replies: 1
    Last Post: 07-23-2014, 10:11 AM
  3. help in converting excel to access
    By Daniel2000 in forum Access
    Replies: 11
    Last Post: 04-25-2013, 01:43 AM
  4. Converting Excel IF to Access iiF???
    By robertr in forum Queries
    Replies: 5
    Last Post: 10-14-2011, 05:53 AM
  5. Converting to access from Excel
    By Alexpi in forum Database Design
    Replies: 3
    Last Post: 05-24-2011, 02:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums