How to generate the MD5 hash of a file using VBA

I am working on a file management application using microsoft access.  Users will be selecting a file to "file" into the relevant directory according to given parameters.  I want to generate the MD5 hash of files that have already been "filed".  When the user goes to file a new file, the md5 hash value of the new file will be calculated - and checked against the existing "filed" files to check for duplicates.  Does anyone know of a source of VBA code that I can use to generate these values.
I havent posted many questions to this forum - have nearly always been able to find exactly what I want by searching other questions.  I have allocated maximum points because I havent been able to find a solution elsewhere.
Who is Participating?
peter57rConnect With a Mentor Commented:
I know nothing about this topic - I'm just aware of the Qs being posted about it.

Here is another Q which deals with a file using the same code.
cteakleAuthor Commented:
Hi Peter57r
I had a look at that post and tried to import the code into my vba without success. However, one difference is that I want to start with a file - not some string and generate the value for the file
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

cteakleAuthor Commented:
Thanks Peter
I will have a try using this code tonight (australian time)
cteakleAuthor Commented:
Hi again Peter - or whomever may be reading these posts.  I remember why I couldnt get this to work before when I tried it on just a string.  I have put Xs around the line of code that causes a problem.  I get a "cannot divide by zero" message, no matter what string I enter.  The problem for me is I have no idea at all what the code is doing, so dont know where to look to try and solve the problem.   The other bit seemed to work though on converting a file to a string in order to use the code.

    ' We do not care about the top most bit or the final bit, the top most bit
    ' will be taken into account in the next stage, the final bit (whether it
    ' is an odd number or not) is being shifted into, so we do not give a jot
    ' about it
XXXX    RShift = (lValue And &H7FFFFFFE) \ m_l2Power(iShiftBits)XXXX
    ' If the top most bit (&H80000000) was set we need to do things differently
    ' as in a normal VB signed long integer the top most bit is used to indicate
    ' the sign of the number, when it is set it is a negative number, so just
    ' deviding by a factor of 2 as above would not work.
    ' NOTE: (lValue And  &H80000000) is equivalent to (lValue < 0), you could
    ' get a very marginal speed improvement by changing the test to (lValue < 0)
cteakleAuthor Commented:
Sorry - my ignorance.  I had to do a bit more research on classes.  I hadnt inserted the module as a class module.  All seems to be working properly now.  Thanks very much for your help Peter
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.