-
WSbushaw
AskWoody LoungerI, too, thought the autonumber-increment method would use the next higher number. But I found duplicates appearing (as described in my previous post) — the newer records were being assigned “old” (archived) numbers even though there were higher active autonumbers — the autonumbering scheme seemed to be “filling holes”. I’ll have to admit that I wasn’t too diligent about repairing/compacting after archiving (removing records from the active table) — that may be part of the problem. Also, and this may be circumstantial, I noticed this problem only after upgrading from Access 97 to 2000.
Autonumber-random is a good idea. With the odds of duplicating an existing record at around 1 in 4 billion, I guess it’s pretty safe (unless you’ve got a fairly big database!). If I were to worry about such odds, I should be buying a lot more Lotto tickets!
-
WSbushaw
AskWoody LoungerI may be mistaken, but I think Access 97 (or is it Excel 97?) may need the 8+3 MS-DOS folder name rather than the civilized one; i.e., try changing “G:New IdeasDummy.xls” to “G:NEWIDE~1Dummy.xls”. (I’m using Office 2000 now, so I can’t check this myself.) It’s possible your MS-DOS folder name is different – check it by viewing the folder’s properties.
Tom
-
WSbushaw
AskWoody LoungerI agree that an autonumber field is a great choice for a primary key. However, I’ve encountered “challenges” with using autoumber primary key fields in the following situation: When I archive records from my “active” table to an “archive” table, I’d like the primary key (the autonumber field) to remain unique across all records in both tables (since it provides the relationship to various other tables). However, once a particular autonumber value is gone from the “active” table, a new record added may be given this value, thus duplicating a primary key in the “archive” table. To avoid this, (based on advice from Charlotte here in Woody’s Lounge), I set up a “master” list of if IDs that are autonumbered. They then relate to an ID field in both the archive and active tables which are not autonumbered. This adds some overhead when adding and deleting records (adding a record to the active table means adding a new record to the master list (with a new and unique-across-both-tables autonumber primary key ID), then actually adding the new record in the active table and copying the master list autonumber value into the field that’s related to the master list ID). Deleting records can be taken care of through referential integrity. It seems like there ought to be a less cumbersome way of doing this — is there???
Regardless, even with this sort of arrangement, I’ve never seen autonumber fields getting re-numbered. Boy, would that be a mess!
Tom
-
WSbushaw
AskWoody LoungerOops… The close file code should read:
‘ Close the dummy workbook (without saving changes)
appExcel.Workbooks(“C:My DocumentsExcel Workbooksdummy file.xls”).Close False -
WSbushaw
AskWoody LoungerEd,
Try this for starters:
Create a new module. Specify the Excel Object Library (find it on the Tools…References list and check it). Then type in the following code:
Option Explicit
Public Function blnExcelFromAccess() as boolean
Dim appExcel As Excel.Application
‘ Link to Excel using automation
Set appExcel = CreateObject(“Excel.Application”)‘ So you can watch what’s happening…
appExcel.Visible = True‘ Open your main workbook
appExcel.Workbooks.Open “C:My DocumentsExcel Workbooksmain file.xls”‘ Calculate (‘read’ values from your dummy file; may not be necessary)
appExcel.Calculate‘ Close the dummy workbook (without saving changes)
appExcel.Workbooks(“C:My DocumentsExcel Workbooksdummy file.xls”) False‘ Done with Excel (omit if you want to leave Excel open)
appExcel.QuitEnd Function
Save the module, then add a RunCode macro command to your macro routine and specify “=blnExcelFromAccess()” as the argument.
This is very bare bones, but it should get you started. I’ll bet you’ll be “doing it all” in VBA before long!
Tom
-
WSbushaw
AskWoody LoungerTry setting the form (or table) field’s format property to “mm/dd/yy”. If the user types in “7/27” and or , “07/27/01” will be displayed (the current year will be assumed). No input mask required. Of course, this does assume you WANT the current year.
-
WSbushaw
AskWoody LoungerFor the form’s On Close event , use VBA (choose Code Builder) and type in the statement:
DoCmd.OpenForm “”
Alternatively, you can use a macro as the On Close event for your form (choose the Macro Builder): Select the “OpenForm” action and specify the Switchboard name as the “Form Name”.
Of course, the Switchboard is a form — its name should be listed on the Forms section of the Database Window.
-
WSbushaw
AskWoody LoungerI tried your suggestions but, alas, to no avail. However, I have found the source of the problem, but can’t explain it.
I created a bare-bones database that reproduced the behavior. The key seems to be: if you have a VBA function call in your query that is not record-contents-dependent (in principle, not a good coding practice anyway, it seems), this behavior seems to appear.
On one computer the function is called once for every record in the table. On the other computer, the function is called only once (it appears to be “smart enough” to know that there is no by-record dependency). If the table is big and/or the function call eats up time, then the performance between the two can be VERY different. In my “real” database, I observed about a 40x difference. Both computers are running the same versions/builds of Access 2000 and VBA. What gives?
Lo and behold, I discovered that one of the computers was running Windows 98 and the other — WIndows 98 SE. The SE computer was running the query “smartly” and fast. I got our IT folks to install SE on the other machine and they now both behave the same way.
Is it plausible that the version of WIndows would affect the way Access processes queries? Seems odd to me…
Here’s the database I used to check this behavior:
tblTestTable:
Simple 1-field (named lngValue) with, say, 1000 records. Structure, etc. of this table doesn’t really matter.Query1:
SELECT tblTestTable.lngValue, blnLogic() AS Logic
FROM tblTestTable;Module:
Option Compare Database
Option Explicit
Option Base 1Public lngTestCount As Long
Public Function blnLogic() As Boolean
blnLogic = True
lngTestCount = lngTestCount + 1
End FunctionPublic Function blnTimeQueryTest() As Boolean
Dim rst As Recordset
lngTestCount = 0
Set rst = CurrentDb.OpenRecordset(“Query1”, dbOpenDynaset)
MsgBox “blnLogic() called ” & lngTestCount & ” times.”, _
vbInformation + vbOKOnly, “Query Timer”
rst.Close
blnTimeQueryTest = True
End FunctExecute blnTimeQueryTest() from the VBA immediate window.
Curiously, if the blnLogic() function is changed to return the long value of the counter, the output of the query shows “1” for every record, indicating the function was still called only once. To me, this is not intuitive behavior (even though it does run faster!). I would have expected the value to increment, record-by-record, as the query is evaluated.
Tom Bushaw
-
WSbushaw
AskWoody LoungerJon,
The “serious problems” Charlotte warns of might be related to her “multiuser” qualification. Envision User 1 getting ready to add a record. The new manual key has been calculated (e.g., DMAX+1) but the record has not yet been added. User 2, meanwhile, is doing the same thing. User 2’s manual key gets calculated to the same value as User 1’s (since User 1’s record hasn’t been added yet). Now, whoever adds their record first “wins”; the other runs into problems…
It doesn’t appear that this particular problem would arise in a single user environment but I wonder if there are other ones that would?
Tom
-
WSbushaw
AskWoody LoungerJon –
Good ideas. Thanks.
Regarding Option 2: If I’m using link tables that use the key values as the linking field this option could present problems. I suppose VBA code could be written to update link table references when records get moved from table to table (and new autonumber keys get assigned), but that seems like it would be a bit of a headache.
Option 3 seems like the way to go, but I need to be sure to check both tables when establishing a new unique number (e.g. DMAX+1 on the union query result). Right?
Any better ideas out there?
Tom Bushaw
Access 2000 (9.0.4402 SR-1) -
WSbushaw
AskWoody LoungerI was about to post a new question but then found this thread that is real close to my problem. I have an “active” table and “archive” table with identical structures (including autonumber keys indexed with no duplicates). When “archiving” a record, I copy it from the active table to the archive table using an append query something like:
INSERT INTO ArchiveTable SELECT ActiveTable.* FROM ActiveTable WHERE (condition that defines a record that needs to be archived);
and then delete those same records from the active table.
This keeps the active table smaller (better performance, presumably). When I need to query all records (e.g., searches on both active and archive records), I query a union of the two tables (hence, the primary keys need to remain unique for the relationships to be properly maintained).
The problem is (as has been pointed out in this thread), the deletion step leaves autonumber “holes” in the active table. When new records are added, the autonumber key assigned may, in fact, duplicate one of the keys of the records that was previously moved over to the archive table. Later, when I try to archive one of these “new” records, a conflict arises because of duplicate key values (this could also occur if I tried to “unarchive” a record; i.e. move it back to the active table).
So… the question is: What is a better way (i.e., a way that actually works!) for maintaining an active-archive table pair while maintaining autonumber uniqueness across BOTH tables?
Tom Bushaw
Access 2000 (9.0.4402 SR-1)
![]() |
Patch reliability is unclear, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Updates seem to have broken Microsoft Edge
by
rebop2020
3 hours, 26 minutes ago -
Wait command?
by
CWBillow
7 minutes ago -
Malwarebytes 5 Free version manual platform updates
by
Bob99
6 hours, 21 minutes ago -
inetpub : Microsoft’s patch for CVE-2025–21204 introduces vulnerability
by
Alex5723
12 hours, 57 minutes ago -
Windows 10 finally gets fix
by
Susan Bradley
21 hours, 50 minutes ago -
AMD Ryzen™ Chipset Driver Release Notes 7.04.09.545
by
Alex5723
23 hours, 10 minutes ago -
Win 7 MS Essentials suddenly not showing number of items scanned.
by
Oldtimer
17 hours, 43 minutes ago -
France : A law requiring messaging apps to implement a backdoor ..
by
Alex5723
1 day, 12 hours ago -
Dev runs Windows 11 ARM on an iPad Air M2
by
Alex5723
1 day, 13 hours ago -
MS-DEFCON 3: Cleanup time
by
Susan Bradley
8 hours, 3 minutes ago -
KB5056686 (.NET v8.0.15) Delivered Twice in April 2025
by
lmacri
4 hours, 44 minutes ago -
How to enable Extended Security Maintenance on Ubuntu 20.04 LTS before it dies
by
Alex5723
2 days ago -
Windows 11 Insider Preview build 26200.5562 released to DEV
by
joep517
2 days, 4 hours ago -
Windows 11 Insider Preview build 26120.3872 (24H2) released to BETA
by
joep517
2 days, 4 hours ago -
Unable to eject external hard drives
by
Robertos42
14 hours, 47 minutes ago -
Saying goodbye to not-so-great technology
by
Susan Bradley
2 hours, 28 minutes ago -
Tech I don’t miss, and some I do
by
Will Fastie
22 minutes ago -
Synology limits hard drives
by
Susan Bradley
3 days, 8 hours ago -
Links from Microsoft 365 and from WhatsApp not working
by
rog7
2 days, 10 hours ago -
WhatsApp Security Advisories CVE-2025-30401
by
Alex5723
3 days, 14 hours ago -
Upgrade Sequence
by
doneager
3 days, 7 hours ago -
Chrome extensions with 6 million installs have hidden tracking code
by
Nibbled To Death By Ducks
1 day, 13 hours ago -
Uninstall “New Outlook” before installing 2024 Home & Business?
by
Tex265
2 days, 6 hours ago -
The incredible shrinking desktop icons
by
Thumper
4 days, 11 hours ago -
Windows 11 Insider Preview Build 22635.5240 (23H2) released to BETA
by
joep517
4 days, 13 hours ago -
Connecting hard drive on USB 3.2 freezes File Explorer & Disk Management
by
WSJMGatehouse
1 day, 12 hours ago -
Shellbag Analyser & Cleaner Update
by
Microfix
1 day, 5 hours ago -
CISA warns of increased breach risks following Oracle Cloud leak
by
Nibbled To Death By Ducks
4 days, 22 hours ago -
Outlook 2024 two sent from email addresses
by
Kathy Stevens
8 hours, 10 minutes ago -
Speeding up 11’s search
by
Susan Bradley
2 days, 10 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.