Results 1 to 10 of 10
  1. #1
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658

    VBA code to calc a check sum for a string variable?

    I don't want to reinvent this wheel in VBA.
    I've got a long text field in a table, that I don't want users or other developers to modify.
    It's a legal notice.

    I'm looking for a simple checksum procedure to validate that the long text hasn't changed.
    It can be in VBA, but since one can't hide certain code in a projext module (.accdb) then it might work better
    if it was some kind of call outside Access, but a call that is standard enough in Windows that there won't be .dll problems in the future.



    Got any ideas?

  2. #2
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    Not sure outside of Access, maybe this for VBA (not my code)

    Function Checksum(text As String) As Long
    Checksum = 0
    For x = 1 To Len(text)
    Checksum = Checksum + (13 * Asc(Mid(text, x, 1)))
    Next x

    End Function

  3. #3
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    @ Bulzie, #2 Thanks, it's a start I'll see what happens with a long string. It'll be a little more complicated with having a copyright year in the long string that needs to be removed first, and I'll see how big the long number gets.

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Depends on how long the text is but in principle you could hash the string and hide the result away somewhere - perhaps as a property. A simple comparison between the hash of the current string and the hidden away value will tell you it has changed - much the same way you would verify a password

  5. #5
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    @ CJ post #4


    hide the result away somewhere - perhaps as a property
    Okey, I'll bite. I had planned to save in a table, but that could easily be changed by a user.
    How does one save data like this in a property? And then use it later?
    It's string data since I have to parse it for language and the checksum for each language.

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Not worth providing an example as properties can be attached to numerous objects - Google ‘ access vba create property’ to give you some idea

    I use them to store commented sql (attached to a querydef) licensing (attached to the fe) authorisation (attached to a table) etc

  7. #7
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    @CJ #6 Thanks for that hint, here's what I found:
    Database.CreateProperty method (DAO) | Microsoft Learn

    If it remains "persistent" as claimed in the Remarks, it just might be the ticket. I'm guessing one runs the code once to create the property, and then it remains through new opens of the .accdx (my idea of persistent).

    I tried the code in the MS sample, it's obviously quite old. And it dies with a RTE in my Access 2021.
    Also missing is the way to read just one property that I might set.

    Seen any better documentation that the MS one that falls quite short for a full explanation?

    Post note: I found this: Microsoft Access - Playing With Database Properties (youtube.com)

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    then it remains through new opens of the .accdx
    don't know what you mean by that. If you mean open a db, create the property, close the db. The property is available when you next open it.

    I tried the code in the MS sample, it's obviously quite old. And it dies with a RTE in my Access 2021.
    Without knowing what the error actually is, unable to comment

    Also missing is the way to read just one property that I might set.
    in the same way you read any property

    objectname.propertyname

    or

    objectname.properties("propertyname").value

  9. #9
    twgonder is offline Expert
    Windows 10 Access 2021
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    @ All This is a good video I found:

    https://youtu.be/hnyC8uYgJBU?si=6roLH9Mkn15OUf-2

    One might consider the simple approach at 20:30 of the video.

  10. #10
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    I had planned to save in a table, but that could easily be changed by a user.
    Tables can be made read only using constraints
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. Replies: 3
    Last Post: 07-20-2020, 01:04 PM
  2. Replies: 2
    Last Post: 04-05-2015, 06:06 PM
  3. calc field producing unwanted spaces amidst the final string
    By kattatonic1 in forum Database Design
    Replies: 7
    Last Post: 07-12-2013, 10:32 AM
  4. Replies: 3
    Last Post: 05-28-2013, 12:53 PM
  5. Replies: 0
    Last Post: 08-10-2011, 11:59 AM

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