{"id":556,"date":"2022-01-24T09:56:48","date_gmt":"2022-01-24T08:56:48","guid":{"rendered":"https:\/\/wiskunst.hjgsoft.nl\/?page_id=556"},"modified":"2022-01-24T10:13:54","modified_gmt":"2022-01-24T09:13:54","slug":"access-backup-en-restore","status":"publish","type":"page","link":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/office-programmeren\/access-backup-en-restore\/","title":{"rendered":"Access backup en restore"},"content":{"rendered":"<p>Wanneer u een mooi project in Access bouwt, dan heeft u vast de behoefte aan een backup- en restore-faciliteit. Nu is het in Access niet zo moeilijk om tabellen en queries te exporteren of te kopi\u00ebren naar een andere database, maar de problemen beginnen pas bij het restoren.<\/p>\n<p>De grootste problemen doen zich voor op de volgende punten:<\/p>\n<ul>\n<li>AutoIncrement-velden (AutoNummering)<\/li>\n<li>Relaties<\/li>\n<\/ul>\n<p>Het zo maar terugzetten van een waarde in een veld van het type AutoNummering levert meteen een probleem op. Dit is op zich niet zo erg tenzij zo&#8217;n veld deel uitmaakt van een relatie.<\/p>\n<p>De relaties tussen tabellen worden in Access bijgehouden in de systeem-tabel MSysRelationships. Het vervelende is echter dat deze tabel niet zomaar te bewerken valt, alleen raadplegen is toegestaan.<\/p>\n<p>We zullen dus voor al deze problemen een oplossing moeten vinden.<\/p>\n<p>Ik heb dat reeds gedaan en wil hier graag deze kennis met u delen. Ik ga er hierbij vanuit dat u (een beetje) weet hoe VBA werkt en dat u een module in Access kunt toevoegen.<\/p>\n<p>De backup-procedure gaat als volgt:<\/p>\n<ul>\n<li>Maak een relatie-tabel aan en vul deze met de waardes uit MSysRelationships<\/li>\n<li>Maak een backup-database aan en copieer alle te backuppen objecten hiernaartoe (inclusief de aangemaakte relatie-tabel)<\/li>\n<li>Verwijder de relatie-tabel weer<\/li>\n<\/ul>\n<p>De restore-procedure gaat als volgt:<\/p>\n<ul>\n<li>Copieer alle objecten uit de backup-database (hierin staat dus ook de relatie-tabel)<\/li>\n<li>Maak de relaties aan (m.b.v. de relatie-tabel)<\/li>\n<li>Verwijder de relatie-tabel<\/li>\n<\/ul>\n<p>De backup-procedure is redelijk straight-foreward.<\/p>\n<p>Bij de restore-procedure moet rekening worden gehouden met het feit dat Access bestaande objecten niet vanzelf zal overschrijven bij een import; hier moeten we dus zelf voor zorgen.<\/p>\n<p>Hieronder zal ik nu de procedures en functies stuk voor stuk geven met daar waar nodig een stukje uitleg. Tezamen vormen ze een module die u in Access kunt gebruiken.<\/p>\n<p>Vooraf dient u nog het volgende te weten:<\/p>\n<p>Alle objecten laat ik bij de naamgeving vooraf gaan door een prefix. Hiervan maak ik in de code gebruik.<\/p>\n<table border=\"1\" cellspacing=\"2\" cellpadding=\"2\">\n<tbody>\n<tr>\n<th>Object<\/th>\n<th>Prefix<\/th>\n<\/tr>\n<tr>\n<td>Tabellen<\/td>\n<td>tbl<\/td>\n<\/tr>\n<tr>\n<td>Queries<\/td>\n<td>qry<\/td>\n<\/tr>\n<tr>\n<td>Formulieren<\/td>\n<td>frm<\/td>\n<\/tr>\n<tr>\n<td>Rapporten<\/td>\n<td>rpt<\/td>\n<\/tr>\n<tr>\n<td>Pagina&#8217;s<\/td>\n<td>pag<\/td>\n<\/tr>\n<tr>\n<td>Macro&#8217;s<\/td>\n<td>mac<\/td>\n<\/tr>\n<tr>\n<td>Modules<\/td>\n<td>mod<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Hieronder staan de functies en procedures:<\/p>\n<hr \/>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Function FileExists(ByVal FileName As String) As Boolean<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 FileExists = (Dir(FileName, vbNormal) &lt;&gt; &#8220;&#8221;)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">End Function<\/span><\/p>\n<p>Deze functie kijkt of de opgegeven bestandsnaam (FileName) bestaat; zo ja dan wordt de functie True, zo nee, dan wordt de functie False. In de FileName mag ook een schijf en\/of pad voorkomen.<\/p>\n<hr \/>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Function BestaatObject(ByVal ObjectNaam As String) As Boolean<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim rs As DAO.Recordset<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Set rs = CurrentDb.OpenRecordset(&#8220;SELECT COUNT(*) FROM MSysObjects WHERE Name = &#8216;&#8221; &amp; ObjectNaam &amp; &#8220;&#8216;&#8221;, dbOpenSnapshot)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 BestaatObject = (rs.Fields(0).Value &gt; 0)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 rs.Close<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Set rs = Nothing<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">End Function<\/span><\/p>\n<p>Deze functie kijkt of een (Access-) object in de huidige access-applicatie voorkomt. Zo ja dan wordt de functie True, zo nee, dan wordt de functie False.<\/p>\n<hr \/>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Sub DropTabel(ByVal tn As String)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 DBEngine(0)(0).TableDefs.Refresh<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 If BestaatObject(tn) Then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 DBEngine(0)(0).TableDefs.Delete tn<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Application.RefreshDatabaseWindow<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 End If<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">End Sub<\/span><\/p>\n<p>Deze procedure haalt de tabel met naam tn weg, als deze bestaat. Tabellen staan in de systeem-collectie\u00a0TableDefs.<\/p>\n<hr \/>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Sub DropQuery(ByVal qn As String)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 DBEngine(0)(0).QueryDefs.Refresh<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 If BestaatObject(qn) Then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 DBEngine(0)(0).QueryDefs.Delete qn<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Application.RefreshDatabaseWindow<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 End If<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">End Sub<\/span><\/p>\n<p>Deze procedure haalt de query met de naam qn weg, als deze bestaat. Queries staan in de systeem-collectie\u00a0QueryDefs.<\/p>\n<hr \/>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Sub DropRapport(ByVal rn As String)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 If BestaatObject(rn) Then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 DoCmd.DeleteObject acReport, rn<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 End If<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">End Sub<\/span><\/p>\n<p>Deze procedure haalt het rapport met de naam rn weg, als deze bestaat.<\/p>\n<hr \/>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Sub VerwijderRelatie(ByVal relname As String)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 DBEngine(0)(0).Relations.Refresh<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 If BestaatObject(relname) Then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 DBEngine(0)(0).Relations.Delete relname<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 End If<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">End Sub<\/span><\/p>\n<p>Deze procedure haalt de relatie met de naam relname weg, als deze bestaat. Relaties staan in de systeem-collectie\u00a0Relations.<\/p>\n<p>De constructie\u00a0DBEngine(0)(0)\u00a0is equivalent met\u00a0CurrentDb.<br \/>\nMet de opdracht\u00a0Application.RefreshDatabaseWindow\u00a0wordt het database-venster ververst.<\/p>\n<hr \/>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Sub MaakRelatieTabel()<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim db As DAO.Database<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim tdf As DAO.TableDef<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim fld As DAO.Field<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim ind As DAO.Index<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim rs(1 To 2) As DAO.Recordset<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim i As Integer<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 If BestaatObject(&#8220;tblRelationShips&#8221;) Then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 DropTabel &#8220;tblRelationShips&#8221;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 End If<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 &#8216;maken van tabel tblRelationShips:<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Set db = CurrentDb()<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Set tdf = db.CreateTableDef(&#8220;tblRelationShips&#8221;) &#8216;hiermee wordt een tabel-definitie gestart<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 With tdf<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Set fld = .CreateField(&#8220;RelationID&#8221;, dbLong) &#8216;maak een veld van type Long aan<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 fld.Attributes = dbAutoIncrField + dbFixedField &#8216;maak het veld AutoNummering<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 .Fields.Append fld &#8216;voeg veld toe aan tabel-definitie<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 .Fields.Append .CreateField(&#8220;rel_naam&#8221;, dbText, 255) &#8216;maak tekst-veld (lengte 255) en voeg toe aan tabel-definitie<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 .Fields.Append .CreateField(&#8220;rel_ref_obj&#8221;, dbText, 255)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 .Fields.Append .CreateField(&#8220;rel_ref_fld&#8221;, dbText, 255)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 .Fields.Append .CreateField(&#8220;rel_obj&#8221;, dbText, 255)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 .Fields.Append .CreateField(&#8220;rel_fld&#8221;, dbText, 255)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 .Fields.Append .CreateField(&#8220;rel_attr&#8221;, dbLong)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 .Fields.Append .CreateField(&#8220;rel_ccol&#8221;, dbLong)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 .Fields.Append .CreateField(&#8220;rel_icol&#8221;, dbLong)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 End With<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 db.TableDefs.Append tdf &#8216;voeg de tabel-definitie toe aan de database<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Set fld = Nothing &#8216;maak object-variabele leeg<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Set tdf = Nothing<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 &#8216;maken van een sleutel-veld:<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Set tdf = db.TableDefs(&#8220;tblRelationShips&#8221;) &#8216;maak contact met de tabel tblRelationShips<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Set ind = tdf.CreateIndex(&#8220;PrimaryKey&#8221;) &#8216;start de index-definitie<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 With ind<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 .Fields.Append .CreateField(&#8220;RelationID&#8221;) &#8216;voeg een index op het veld RelationID toe<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 .Unique = False<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 .Primary = True &#8216;het sleutel-veld<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 End With<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 tdf.Indexes.Append ind &#8216;voeg de index toe aan de database<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 tdf.Indexes.Refresh<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Set ind = Nothing<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Set tdf = Nothing<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Set db = Nothing<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Application.RefreshDatabaseWindow<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 &#8216;vullen van de nieuwe tabel:<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Set rs(1) = CurrentDb.OpenRecordset(&#8220;SELECT szRelationship, szReferencedObject, szReferencedColumn, szObject, szColumn, grbit, ccolumn, icolumn FROM MSysRelationships &#8220;, dbOpenSnapshot) &#8216;maak een record-set om te lezen<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 If Not rs(1).EOF Then &#8216;als record-set niet leeg is dan<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Set rs(2) = CurrentDb.OpenRecordset(&#8220;tblRelationShips&#8221;, dbOpenDynaset) &#8216;maak contact met tabel om te muteren<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 rs(1).MoveFirst &#8216;ga naar het eerste record<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Do While Not rs(1).EOF &#8216;zolang er nog records zijn<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 rs(2).AddNew &#8216;voeg een nieuw record toe<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 For i = 0 To 7<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 rs(2).Fields(i + 1).Value = rs(1).Fields(i).Value &#8216;vul de overeenkomstige velden<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Next i<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 rs(2).Update &#8216;bewaar het gevulde record<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 rs(1).MoveNext &#8216;ga naar het volgende record<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Loop<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 rs(2).Close &#8216;sluit record-set\/tabel<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Set rs(2) = Nothing<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 End If<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 rs(1).Close<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Set rs(1) = Nothing<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">End Sub<\/span><\/p>\n<p>Deze procedure maakt een relatie-tabel aan en vult deze met de huidige relaties.<\/p>\n<hr \/>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Sub DropRelatieTabel()<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 DropTabel &#8220;tblRelationShips&#8221;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">End Sub<\/span><\/p>\n<p>Deze procedure gooit de relatie-tabel weg.<\/p>\n<hr \/>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Sub MaakRelaties()<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim db As DAO.Database<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim rel As DAO.Relation<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim fld As DAO.Field<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim rs As DAO.Recordset<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 If BestaatObject(&#8220;tblRelationShips&#8221;) Then<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Set db = CurrentDb()<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Set rs = db.OpenRecordset(&#8220;tblRelationShips&#8221;, dbOpenSnapshot)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 If Not rs.EOF Then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 rs.MoveFirst<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Do While Not rs.EOF<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 Set rel = db.CreateRelation(rs.Fields(&#8220;rel_naam&#8221;).Value) &#8216;geef relatie een naam<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 With rel<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .Table = rs.Fields(&#8220;rel_ref_obj&#8221;).Value &#8216;wat is de originele tabel (de 1-kant)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .ForeignTable = rs.Fields(&#8220;rel_obj&#8221;).Value &#8216;wat is de beeld-tabel (de n-kant)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .Attributes = rs.Fields(&#8220;rel_attr&#8221;).Value\u00a0 &#8216;wat zijn de attributen van de relatie (integriteit, cascading deletion\/update etc.)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Set fld = .CreateField(rs.Fields(&#8220;rel_ref_fld&#8221;).Value) &#8216;wat is het sleutel-veld (aan de 1-kant)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 fld.ForeignName = rs.Fields(&#8220;rel_fld&#8221;).Value &#8216;wat is de vreemde-sleutel (aan de n-kant)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 .Fields.Append fld<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 End With<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 db.Relations.Append rel &#8216;voeg de relatie toe aan de database<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 Set fld = Nothing<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 Set rel = Nothing<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 rs.MoveNext<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Loop<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 End If<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 rs.Close<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Set rs = Nothing<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Set db = Nothing<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 End If<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">End Sub<\/span><\/p>\n<p>Deze procedure maakt de relaties aan.<\/p>\n<hr \/>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Sub BackUpObjecten()<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim dbname As String<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim ws As Workspace<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim db As Database<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim rs As DAO.Recordset<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim rapporten() As String<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim queries() As String<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim tabellen() As String<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim prfx As String<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim t As Integer<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim SQL As String<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 &#8216;inventariseer welke objecten in aanmerking komen om naar de backup te gaan:<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ReDim rapporten(0 To 0)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ReDim queries(0 To 0)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ReDim tabellen(0 To 0)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 SQL = &#8220;SELECT Name FROM MSysObjects WHERE Type &lt;&gt; 8&#8221; &#8216;in MSysObjects staan alle Access-objecten; Type=8 duidt op een relatie-naam<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Set rs = CurrentDb.OpenRecordset(SQL, dbOpenSnapshot)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 If Not rs.EOF Then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 rs.MoveFirst<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Do While Not rs.EOF<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 prfx = UCase(Left(rs.Fields(0).Value, 3)) &#8216;bepaal de prefix van het object<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 If prfx = &#8220;QRY&#8221; Then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 ReDim Preserve queries(0 To UBound(queries) + 1)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 queries(UBound(queries)) = rs.Fields(0).Value<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 End If<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 If prfx = &#8220;RPT&#8221; Then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 ReDim Preserve rapporten(0 To UBound(rapporten) + 1)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 rapporten(UBound(rapporten)) = rs.Fields(0).Value<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 End If<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 If prfx = &#8220;TBL&#8221; Then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 ReDim Preserve tabellen(0 To UBound(tabellen) + 1)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 tabellen(UBound(tabellen)) = rs.Fields(0).Value<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 End If<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 rs.MoveNext<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Loop<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 End If<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 rs.Close<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Set rs = Nothing<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 dbname = Application.CurrentProject.Path &amp; &#8220;\\backupdb.bak.mdb&#8221; &#8216;maak backup-databasse aan (bestand)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 If FileExists(dbname) Then &#8216;als backup-database al bestaat dan<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Kill dbname &#8216;delete het<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 End If<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Set ws = DBEngine.Workspaces(0)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Set db = ws.CreateDatabase(dbname, dbLangGeneral) &#8216;cre\u00eber backup-database (inhoudelijk)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 db.Close<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Set db = Nothing<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ws.Close<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Set ws = Nothing<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 For t = 1 To UBound(rapporten)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 DoCmd.CopyObject dbname, rapporten(t), acReport, rapporten(t) &#8216;copieer alle rapporten naar de backup-database<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Next t<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 For t = 1 To UBound(queries)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 DoCmd.CopyObject dbname, queries(t), acQuery, queries(t)\u00a0&#8216;copieer alle queries naar de backup-database<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Next t<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 For t = 1 To UBound(tabellen)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 DoCmd.CopyObject dbname, tabellen(t), acTable, tabellen(t)\u00a0&#8216;copieer alle tabellen naar de backup-database<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Next t<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 MsgBox &#8220;De backup is gemaakt onder de naam: &#8221; &amp; dbname, vbOKOnly + vbInformation, &#8220;BACKUP KLAAR&#8221;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">End Sub<\/span><\/p>\n<p>Deze procedure maakt een backup-database aan en copieert daarna alle tabellen (tbl&#8230;), alle queries (qry&#8230;) en alle rapporten (rpt&#8230;) van de huidige Access-applicatie naar de backup-database.<\/p>\n<hr \/>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Sub VerwijderRelaties()<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim rs As DAO.Recordset<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim SQL As String<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim relname() As String<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim i As Integer, a As Integer<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 a = 0<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 SQL = &#8220;SELECT szRelationship FROM MSysRelationships WHERE LEFT(UCASE(szRelationship),3) = &#8216;TBL'&#8221;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Set rs = CurrentDb.OpenRecordset(SQL, dbOpenSnapshot)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 If Not rs.EOF Then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 ReDim relname(1 To 1)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 a = 1<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 rs.MoveFirst<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Do While Not rs.EOF<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 relname(UBound(relname)) = rs.Fields(0).Value<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 rs.MoveNext<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 If Not rs.EOF Then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 ReDim Preserve relname(1 To UBound(relname) + 1)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 End If<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Loop<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 End If<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 rs.Close<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Set rs = Nothing<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 If a &gt; 0 Then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 For i = 1 To UBound(relname)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 VerwijderRelatie relname(i)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Next i<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 End If<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">End Sub<\/span><\/p>\n<p>Deze procedure verwijdert alle huidige relaties.<\/p>\n<hr \/>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Sub RestoreObjecten()<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim rs As DAO.Recordset<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim db As DAO.Database<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim dbname As String<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim SQL As String<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim prfx As String<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim doc As String<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dim import As Boolean<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 dbname = Application.CurrentProject.Path &amp; &#8220;\\backupdb.bak.mdb&#8221;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 If FileExists(dbname) Then &#8216;als de backup-database is gevonden<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 VerwijderRelaties<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Set db = DBEngine.Workspaces(0).OpenDatabase(dbname) \u00a0 &#8216;maak contact met de backup-database<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 SQL = &#8220;SELECT Name FROM MSysObjects WHERE Type &lt;&gt; 8&#8221;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Set rs = db.OpenRecordset(SQL, dbOpenSnapshot)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 If Not rs.EOF Then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 rs.MoveFirst<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Do While Not rs.EOF<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 doc = rs.Fields(0).Value &#8216;naam van het object<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 prfx = UCase(Left(doc, 3)) &#8216;bepaal prefix<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 Select Case prfx<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Case &#8220;TBL&#8221;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 If BestaatObject(doc) Then &#8216;als tabel in de huidige database al bestaat<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 DropTabel doc<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 End If<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 DoCmd.TransferDatabase acImport, &#8220;Microsoft Access&#8221;, dbname, acTable, doc, doc, False &#8216;importeer de tabel<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Case &#8220;QRY&#8221;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 If BestaatObject(doc) Then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 DropQuery doc<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 End If<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 DoCmd.TransferDatabase acImport, &#8220;Microsoft Access&#8221;, dbname, acQuery, doc, doc, False<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Case &#8220;RPT&#8221;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 If BestaatObject(doc) Then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 DropRapport doc<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 End If<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 DoCmd.TransferDatabase acImport, &#8220;Microsoft Access&#8221;, dbname, acReport, doc, doc, False<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 End Select<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 rs.MoveNext<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Loop<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 End If<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 rs.Close<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 db.Close<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Set rs = Nothing<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Set db = Nothing<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 MsgBox &#8220;De import\/restore is klaar!&#8221;, vbOKOnly, &#8220;KLAAR&#8221;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Else<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 MsgBox &#8220;Backup-bestand niet gevonden!&#8221;, vbOKOnly +\u00a0 \u00a0vbInformation, &#8220;KLAAR&#8221;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 End If<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">End Sub<\/span><\/p>\n<p>Deze procedure importeert de objecten (tabellen, queries en rapporten) uit de backup-database. Als een object al in de huidige database bestaat wordt deze eerst verwijderd.<\/p>\n<hr \/>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Sub Backup()<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 MaakRelatieTabel<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 BackUpObjecten<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 DropRelatieTabel<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">End Sub<\/span><\/p>\n<p>Deze procedure maakt een backup zoals in het begin van dit hoofdstuk staat beschreven.<\/p>\n<hr \/>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">Sub Restore()<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 RestoreObjecten<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 MaakRelaties<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 DropRelatieTabel<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">End Sub<\/span><\/p>\n<p>Deze procedure maakt een restore zoals \u00a0in het begin van dit hoofdstuk staat beschreven.<\/p>\n<hr \/>\n<p>Wanneer u alle bovenstaande procedures en functies in een module zet, dan heeft u een aardige tool om te backuppen en te restoren.<\/p>\n<p>Bij het backuppen en restoren wordt er onderscheid gemaakt in de objecten door middel van een prefix. Dit is gewoon een handigheidje, omdat ik nu eenmaal lijdt aan beroepsdeformatie en alle objecten in de computer-wereld vooraf laat gaan door een prefix.<\/p>\n<p>Het is natuurlijk ook mogelijk om onderscheid tussen de verschillende objecten te maken door te kijken naar het veld Type in de systeem-tabel MSysObjects. Hieronder een overzicht van de verschillende waardes voor Type per object:<\/p>\n<table border=\"1\" cellspacing=\"2\" cellpadding=\"2\">\n<tbody>\n<tr>\n<th>Object<\/th>\n<th>Type-waarde<\/th>\n<\/tr>\n<tr>\n<td>Tabellen<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>Queries<\/td>\n<td>5<\/td>\n<\/tr>\n<tr>\n<td>Formulieren<\/td>\n<td>-32768<\/td>\n<\/tr>\n<tr>\n<td>Rapporten<\/td>\n<td>-32764<\/td>\n<\/tr>\n<tr>\n<td>Pagina&#8217;s<\/td>\n<td>-32756<\/td>\n<\/tr>\n<tr>\n<td>Macro&#8217;s<\/td>\n<td>-32766<\/td>\n<\/tr>\n<tr>\n<td>Modules<\/td>\n<td>-32761<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Als laatste is het belangrijk dat wanneer u een module maakt met de bovenstaande procedures en functies dat u in de VBA-editor een verwijzing legt naar de &#8220;DAO object library&#8221;; kies in de module de optie &#8220;Verwijzingen&#8230;&#8221; uit het menu &#8220;Extra&#8221; en zoek naar &#8220;Microsoft DAO &#8230;&#8221; en zet hier een vinkje voor.<\/p>\n<p>U kunt\u00a0<a href=\"https:\/\/wiskunst.nl\/wp-content\/uploads\/2022\/01\/modBackupRestore.zip\">hier<\/a>\u00a0de gehele module downloaden.<\/p>\n<p>Ik hoop dat deze informatie nuttig voor u is, en dat u heeft gevonden wat u zocht.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wanneer u een mooi project in Access bouwt, dan heeft u vast de behoefte aan een backup- en restore-faciliteit. Nu is het in Access niet zo moeilijk om tabellen en queries te exporteren of te kopi\u00ebren naar een andere database, maar de problemen beginnen pas bij het restoren. De grootste problemen doen zich voor op [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":554,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"templates\/template-full-width.php","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"class_list":["post-556","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Access backup en restore - Wiskunst<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wiskunst.nl\/index.php\/programmeren1\/office-programmeren\/access-backup-en-restore\/\" \/>\n<meta property=\"og:locale\" content=\"nl_NL\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Access backup en restore - Wiskunst\" \/>\n<meta property=\"og:description\" content=\"Wanneer u een mooi project in Access bouwt, dan heeft u vast de behoefte aan een backup- en restore-faciliteit. Nu is het in Access niet zo moeilijk om tabellen en queries te exporteren of te kopi\u00ebren naar een andere database, maar de problemen beginnen pas bij het restoren. De grootste problemen doen zich voor op [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wiskunst.nl\/index.php\/programmeren1\/office-programmeren\/access-backup-en-restore\/\" \/>\n<meta property=\"og:site_name\" content=\"Wiskunst\" \/>\n<meta property=\"article:modified_time\" content=\"2022-01-24T09:13:54+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Geschatte leestijd\" \/>\n\t<meta name=\"twitter:data1\" content=\"11 minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/wiskunst.nl\\\/index.php\\\/programmeren1\\\/office-programmeren\\\/access-backup-en-restore\\\/\",\"url\":\"https:\\\/\\\/wiskunst.nl\\\/index.php\\\/programmeren1\\\/office-programmeren\\\/access-backup-en-restore\\\/\",\"name\":\"Access backup en restore - Wiskunst\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wiskunst.nl\\\/#website\"},\"datePublished\":\"2022-01-24T08:56:48+00:00\",\"dateModified\":\"2022-01-24T09:13:54+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/wiskunst.nl\\\/index.php\\\/programmeren1\\\/office-programmeren\\\/access-backup-en-restore\\\/#breadcrumb\"},\"inLanguage\":\"nl-NL\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/wiskunst.nl\\\/index.php\\\/programmeren1\\\/office-programmeren\\\/access-backup-en-restore\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/wiskunst.nl\\\/index.php\\\/programmeren1\\\/office-programmeren\\\/access-backup-en-restore\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/wiskunst.nl\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Programmeren\",\"item\":\"https:\\\/\\\/wiskunst.nl\\\/index.php\\\/programmeren1\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Office programmeren\",\"item\":\"https:\\\/\\\/wiskunst.nl\\\/index.php\\\/programmeren1\\\/office-programmeren\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Access backup en restore\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/wiskunst.nl\\\/#website\",\"url\":\"https:\\\/\\\/wiskunst.nl\\\/\",\"name\":\"Wiskunst\",\"description\":\"2\u221e\u2227&gt;\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/wiskunst.nl\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"nl-NL\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Access backup en restore - Wiskunst","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/office-programmeren\/access-backup-en-restore\/","og_locale":"nl_NL","og_type":"article","og_title":"Access backup en restore - Wiskunst","og_description":"Wanneer u een mooi project in Access bouwt, dan heeft u vast de behoefte aan een backup- en restore-faciliteit. Nu is het in Access niet zo moeilijk om tabellen en queries te exporteren of te kopi\u00ebren naar een andere database, maar de problemen beginnen pas bij het restoren. De grootste problemen doen zich voor op [&hellip;]","og_url":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/office-programmeren\/access-backup-en-restore\/","og_site_name":"Wiskunst","article_modified_time":"2022-01-24T09:13:54+00:00","twitter_card":"summary_large_image","twitter_misc":{"Geschatte leestijd":"11 minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/office-programmeren\/access-backup-en-restore\/","url":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/office-programmeren\/access-backup-en-restore\/","name":"Access backup en restore - Wiskunst","isPartOf":{"@id":"https:\/\/wiskunst.nl\/#website"},"datePublished":"2022-01-24T08:56:48+00:00","dateModified":"2022-01-24T09:13:54+00:00","breadcrumb":{"@id":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/office-programmeren\/access-backup-en-restore\/#breadcrumb"},"inLanguage":"nl-NL","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wiskunst.nl\/index.php\/programmeren1\/office-programmeren\/access-backup-en-restore\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/office-programmeren\/access-backup-en-restore\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wiskunst.nl\/"},{"@type":"ListItem","position":2,"name":"Programmeren","item":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/"},{"@type":"ListItem","position":3,"name":"Office programmeren","item":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/office-programmeren\/"},{"@type":"ListItem","position":4,"name":"Access backup en restore"}]},{"@type":"WebSite","@id":"https:\/\/wiskunst.nl\/#website","url":"https:\/\/wiskunst.nl\/","name":"Wiskunst","description":"2\u221e\u2227&gt;","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wiskunst.nl\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"nl-NL"}]}},"_links":{"self":[{"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/pages\/556","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/comments?post=556"}],"version-history":[{"count":4,"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/pages\/556\/revisions"}],"predecessor-version":[{"id":561,"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/pages\/556\/revisions\/561"}],"up":[{"embeddable":true,"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/pages\/554"}],"wp:attachment":[{"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/media?parent=556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}