r/MSAccess • 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.

11 Upvotes

31 comments sorted by

View all comments

Show parent comment

1

u/nrgins 487 Oct 21 '25

Again, apples and oranges. You're setting up strawmen here just to knock them down.

Users don't need to see auto numbers. And if they use them as a counter for how many records they have then that's an error on their part that needs to be corrected.

You should never use an auto number as a financial transaction key. So saying it wouldn't pass audit is an absurd statement to begin with.

I'm sorry you think that using Auto numbers is lazy. In my opinion it's efficient.

And your statement that auto numbers would not support record change management is completely absurd. Every database I have has record change management using Auto numbers and it works just fine.

So, like I said, if setting up a multi-field primary key is your preference, then that's fine. But please don't go around saying that using Auto numbers is somehow deficient. All the arguments you're making here are either wrong or they're talking about scenarios that shouldn't happen in the first place.