gloNumber_n = Forms!frmStudies!gKEYFIELD 'remember this voor later
DoCmd.RunSQL ("UPDATE tbArchiveStudies SET gArchive_b = False WHERE (gKEYFIELD= " & Str(Forms!frmStudies!gKEYFIELD) & ");") 'set the archive flag to False
DoCmd.RunSQL ("INSERT INTO tbStudies SELECT * FROM tbArchiveStudies WHERE (gArchive_b=False);")
'add the audit rapports of this study to tbInspecties
DoCmd.RunSQL ("INSERT INTO tbInspecties SELECT tbArchiveInspecties.* FROM tbArchiveInspecties LEFT JOIN tbArchiveStudies ON tbArchiveInspecties.iSTUDYKEY = tbArchiveStudies.gKEYFIELD WHERE (tbArchiveStudies.gArchive_b=False);")
'delete these auditrapports from tbArchiveInspecties
DoCmd.RunSQL ("DELETE tbArchiveInspecties.* FROM tbArchiveInspecties LEFT JOIN tbArchiveStudies ON tbArchiveInspecties.iSTUDYKEY = tbArchiveStudies.gKEYFIELD WHERE (tbArchiveStudies.gArchive_b=False);")
DoCmd.RunSQL ("DELETE FROM tbArchiveStudies WHERE (gArchive_b=False);")