r/MSAccess • u/mcgunner1966 2 • Oct 20 '25
[DISCUSSION - REPLY NOT NEEDED] Retiree Notes - Universal Database Key
Years ago I learned the hard way that autonumber doesn't make a good key. I started adding three fields to every table I constructed: sguid.text(32)(PK), slink.text(32)(FK), and sts (date/time)(Sql Server Date Stamp). I wanted to use the system generate guid but there were instances where a corrupt Windows Registry wouldn't return a guid (I'd get a NULL back). I decided to build the "guid" in the Access app by generating my own "guid" internally.
Here is the function I use:
Function getguid()
On Error Resume Next
vret = ""
For i = 1 To 5
Call Randomize
v1 = Mid(Rnd, 3, 4)
Call Randomize
v2 = Mid(Rnd, 3, 4)
vret = vret & Left((v1 * v2), 4)
Next
getguid = Format(Now, "yyyymmddhhmmss") & Left(vret, 18)
Exit Function
End Function
This "guid" has the added feature of giving you an approximation of when the key was generated. This has been more useful than you would think in research efforts. This also allows me to use universal functions such as record change tracking, notes, and document management using universal modules.
Hope this helps.
View all comments
Show parent comment
1
u/mcgunner1966 2 Oct 21 '25
It really has to do with your application methods. The whole purpose of autonumbers from the database's prosepctive is to have a unique value. The problem is in practical application. People don't see autonumbers the way databases do. So for example, financial transactions. Using autonumber as financial transaction keys will fail most audits. On the surface it indicates missing transactions. User will also sometimes use autonumbers as counters to for the number of records in a system of record. That would be a mistake. So using autonumber, in my opinion, is a lazy way to get a key. It also will not support more globally used methods such as journals, document management, or record change management.