I’m trying to setup my database so that the user can manually archive records manually. Right now we have open cases and closed cases all in the same table. When a case closes I would like to be able to use a command button to put the closed case in a separate table. The real problem I’m having is getting all the data for each record to ship to the archive table. In my form there are many controls on the form itself and there are also 2 subforms, where the main form is getting its data from tblMaster, and the subforms getting their data from tblDetails and tblVictims. Code examples and or suggestions would be great!
Thanks
Jols
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Archiving records
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Archiving records
- This topic has 13 replies, 7 voices, and was last updated 24 years, 1 month ago.
AuthorTopicWSdjoly
AskWoody LoungerJanuary 11, 2001 at 12:40 pm #351763Viewing 0 reply threadsAuthorReplies-
WSpeterguk
AskWoody LoungerJanuary 11, 2001 at 2:55 pm #510061Hi Jols
Don’t know whether i can help, but i have a similar situation where i have open orders in one table, and once closed, they are moved to another table.
What i do is use two queries which run invisibly to the user. The first runs an append query (to the closed orders table) picking up the order number from the user’s form, and then i close the form, display a “record archived” message, and then run a delete query on the open table.
Hope this helps………………
Peter
-
WSmcneilkm
AskWoody LoungerJanuary 11, 2001 at 6:14 pm #510077Hi, I am doing the same thing. It seems to work very well. I have a main table and three other tables all supporting a main form and three subforms. When I archive a record from the main table/main form I run a query which adds it to the archive table. Another query takes the supporting information from the subforms records and adds them to there own archive tables. Finally i run queries which delete the newly archived records from the current tables. I have examples I can email to you if you would like. I also am reversing the archive by reversing the query steps. I perform all of this as the user logs on it picks up the records assigned to them and allows the user to pick and choose the records he/she wants to archive. All the user does is check a box on a form next to the record they want to archive.
Kevin
-
WSdjoly
AskWoody LoungerJanuary 12, 2001 at 3:08 am #510178 -
WScharlotte
AskWoody LoungerJanuary 12, 2001 at 5:40 am #510194 -
WSbushaw
AskWoody LoungerFebruary 12, 2001 at 6:06 pm #514377I 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) -
WSJon Dean
AskWoody LoungerFebruary 12, 2001 at 7:38 pm #514390To all on this particular thread:
Charlotte is right about the compacting issue and potential holes in the autonumber sequence so here’s some ideas:
1 Compact before you archive. This may be impractical so;
2 Don’t take the Autonumber key with the record when you archive it (or even return it to live). This way, Access will automatically generate a new, unique key everytime a record is added to a table. This does mean that the record changes key when you archive it but since the autonumber’s purpose is purely to maintain uniqueness, this shouldn’t be a problem. If it is;
3 Don’t use Autonumbers for your key fields. Use a manually entered number or text field. You can write a bit of VBA to automatically generate the next number in a data entry form to save having to constantly try to remember what the last number was but you can change it to any unique number. This last method means your key fields are kept intact no matter how many times the record changes tables. -
WSbushaw
AskWoody LoungerFebruary 12, 2001 at 8:29 pm #514394Jon –
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) -
WScharlotte
AskWoody LoungerFebruary 13, 2001 at 6:09 am #514444Maintaining non-automatic keys in a multiuser database can present some serious problems, and I don’t recommend it. One other way you can handle this is by subclassing the records.
To do that, you create a table that holds nothing but an autonumber key and possibly a field to tell you whether this record is active or archived. That table is the center of your design, and it has a one-to-one connection to your active and archive tables, with referential integrity and cascading updates enabled. When you create a new record, you create it in that first table and then create it in the Active table. Referential integrity and cascading updates can be used to see to it that the new active record inherits the PK from the first table as its primary key. When you move the record to an archive table, the key moves with it, along with the connection to the first table. All that changes is the location of the record. Since the key is generated in the first table, you never should have orphaned records.
-
WSJon Dean
AskWoody Lounger -
WSbushaw
AskWoody LoungerFebruary 13, 2001 at 5:23 pm #514509Jon,
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
-
Gwb
AskWoody LoungerFebruary 13, 2001 at 6:45 pm #514517I am makeing a purchase order/inventory program where they wanted either to manually enter a po number or have the system assign one. I have a table called LabelFile and used this code on my PurchaseOrder entry form to assign a number. So far it works, haven’t tested in a multi-user situation, though. Here is the code:
Private Sub PONumber_Exit(Cancel As Integer)
If Me!PONumber = 0 Then
Dim intPONumber As Integer
Dim db As DAO.Database
Dim rst As RecordsetSet db = CurrentDb()
Set rst = db.OpenRecordset(“Labelfile”)
intPONumber = rst!PONumber + 1With rst
.Edit
!PONumber = intPONumber
.Update
End WithI suppose the problem will be when a PO number is entered that is already in the system, or the system tries to assign one that is already on file.
rst.Close
Me!PONumber = intPONumber
End If -
WScharlotte
AskWoody LoungerFebruary 14, 2001 at 2:42 am #514572Do NOT make your PO the primary key. Go ahead and make it a unique key (indexed, no duplicates) but don’t make it the primary key. Make your primary key an autonumber that the user never sees. When they enter a new record and assign it a PO, the system will automatically generate an autonumber key for the record. Then when they decide that their current PO numbering system isn’t adequate and they have to change it, you’re a hero because it won’t break your application. Don’t believe anyone who tells you it won’t change. Years and years of experience tells me it will.
It looks like you’re holding a single value in LabelFile and looking it up to create the next number, and this is a fairly common approach to this kind of key. One thing to remember, though, is that you’re working with the version of the database that’s in memory on your machine. Other users are working with the copy that’s in memory on their machines. The various copies don’t get synced constantly, even with a split front-end/back-end, so you may need to force a refresh to be sure that the number you just added turns up in the back-end sooner rather than later. This becomes especially critical if users are actually keying in POs, with you playing catchup to see to it that the number they entered gets saved as the latest PO number.
To handle the problem of the PO’s, your code needs to do two things, test to see if the value they enter or you created already exists in an order record, and then attempt to create the new record and trap any errors. If you get a duplicate key or index error, increment the PO number using your code or something like it and try again. Usually, you handle this kind of thing in a Do…Until loop, looping until you get a PO number you can use without a duplicate key or index error.
Your code updates your LabelFile table, but it doesn’t indicate how you actually create your records using the PO number. The table where the PO number is actually assigned to an order transaction is the one is the one that will get you into trouble, and this is where you need an autonumber. If you used an autonumber in the records as the PK but display the associated PO on the screen and for searches, you wouldn’t be plagued with the problem of a user incorrectly entering the PO and then wanting to go back and change it. If it isn’t the primary key, changing it isn’t such a problem.
-
WScharlotte
AskWoody Lounger
-
-
-
-
Viewing 0 reply threads -

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
-
Looking for personal finance software with budgeting capabilities
by
cellsee6
1 hour, 2 minutes ago -
ATT/Yahoo Secure Mail Key
by
Lil88reb
12 hours, 21 minutes ago -
Devices with apps using sprotect.sys driver might stop responding
by
Alex5723
16 hours, 43 minutes ago -
Neowin – 20 times computers embarrassed themselves with public BSODs and goofups
by
EP
1 day, 1 hour ago -
Slow Down in Windows 10 performance after March 2025 updates ??
by
arbrich
3 hours, 33 minutes ago -
Mail from certain domains not delivered to my outlook.com address
by
pumphouse
9 hours, 41 minutes ago -
Is data that is in OneDrive also taking up space on my computer?
by
WShollis1818
20 hours, 21 minutes ago -
Nvidia just fixed an AMD Linux bug
by
Alex5723
2 days, 12 hours ago -
50 years and counting
by
Susan Bradley
2 hours, 40 minutes ago -
Fix Bluetooth Device Failed to Delete in Windows Settings
by
Drcard:))
1 day, 18 hours ago -
Licensing and pricing updates for on-premises server products coming July 2025
by
Alex5723
2 days, 23 hours ago -
Edge : Deprecating window.external.getHostEnvironmentValue()
by
Alex5723
2 days, 23 hours ago -
Rethinking Extension Data Consent: Clarity, Consistency, and Control
by
Alex5723
2 days, 23 hours ago -
OneNote and MS Word 365
by
CWBillow
3 days, 1 hour ago -
Ultimate Mac Buyers Guide 2025: Which Mac is Right For You?
by
Alex5723
3 days, 1 hour ago -
Intel Unison support ends on Windows 11 in June
by
Alex5723
3 days, 1 hour ago -
April 2025 — still issues with AMD + 24H2
by
Kevin Jones
16 hours, 51 minutes ago -
Windows 11 Insider Preview build 26200.5518 released to DEV
by
joep517
3 days, 13 hours ago -
Windows 11 Insider Preview build 26120.3671 (24H2) released to BETA
by
joep517
3 days, 13 hours ago -
Forcing(or trying to) save Local Documents to OneDrive
by
PateWilliam
3 days, 22 hours ago -
Hotpatch for Windows client now available (Enterprise)
by
Alex5723
3 days, 9 hours ago -
MS-DEFCON 2: Seven months and counting
by
Susan Bradley
2 days, 10 hours ago -
My 3 monitors go black & then the Taskbar is moved to center monitor
by
saturn2233
4 days, 6 hours ago -
Apple backports fixes
by
Susan Bradley
3 days, 13 hours ago -
Win 11 24H2 will not install
by
Michael1950
2 days, 11 hours ago -
Advice to convert MBR to GPT and install Windows 11 Pro on unsupported PC
by
Andy M
1 day, 4 hours ago -
Photos from iPhone to Win 10 duplicating/reformatting to .mov
by
J9438
2 days, 19 hours ago -
Thunderbird in trouble. Here comes Thundermail
by
Alex5723
1 day, 7 hours ago -
Get back ” Open With” in context menus
by
CWBillow
4 days, 21 hours ago -
Many AMD Ryzen 9800X3D on ASRock have died
by
Alex5723
3 days, 13 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.