Student Record Archiving in Microsoft Access
Submitted by rinvizle on Thursday, July 14, 2016 - 08:06.
In this tutorial we will create Student Record Archieving in MSAccess. When you deal with a lot of Microsoft Access data, involving many records in your database tables, you may not always wish to have all of that data stored in the one main table, that is accessed on a regular basis. You may need to regularly archive your Access data so that you are only dealing with the most current up to date records. In this process can be quite done easily by manually running an Append Query to copy the records to the archive table and then by running a Delete Query to remove the records from the main table. I have Example Images and Code below.
Don't forget to Like and Share. Enjoy Coding.
Sample Code
Script for the Records- Option Compare Database
- Private Sub cmdArchiveData_Click()
- Dim strSQLAppend As String
- Dim strSQLDelete As String
- Dim errLoop As Error
- Dim dteExpiry As Date
- dteExpiry = DateAdd("yyyy", -2, Date)
- strSQLAppend = "INSERT INTO tblExpiredStudents " & _
- "( strStudentID, strFirstName, strLastName, strAddress1, " & _
- "strAddress2, strCity, strCounty, strPostCode, strTelephone, " & _
- "[hypE-mailAddress], dtmDOB, dtmEnrolled, strCourseID ) " & _
- "SELECT tblStudentInformation.strStudentID, " & _
- "tblStudentInformation.strFirstName, " & _
- "tblStudentInformation.strLastName, " & _
- "tblStudentInformation.strAddress1, " & _
- "tblStudentInformation.strAddress2, " & _
- "tblStudentInformation.strCity, " & _
- "tblStudentInformation.strCounty, " & _
- "tblStudentInformation.strPostCode, " & _
- "tblStudentInformation.strTelephone, " & _
- "tblStudentInformation.[hypE-mailAddress], " & _
- "tblStudentInformation.dtmDOB, " & _
- "tblStudentInformation.dtmEnrolled, " & _
- "tblStudentInformation.strCourseID " & _
- "FROM tblStudentInformation " & _
- "WHERE tblStudentInformation.dtmEnrolled <= #" & dteExpiry & "#;"
- strSQLDelete = "DELETE tblStudentInformation.strStudentID, " & _
- "tblStudentInformation.strFirstName, " & _
- "tblStudentInformation.strLastName, " & _
- "tblStudentInformation.strAddress1, " & _
- "tblStudentInformation.strAddress2, " & _
- "tblStudentInformation.strCity, " & _
- "tblStudentInformation.strCounty, " & _
- "tblStudentInformation.strPostCode, " & _
- "tblStudentInformation.strTelephone, " & _
- "tblStudentInformation.[hypE-mailAddress], " & _
- "tblStudentInformation.dtmDOB, " & _
- "tblStudentInformation.dtmEnrolled, " & _
- "tblStudentInformation.strCourseID " & _
- "FROM tblStudentInformation " & _
- "WHERE tblStudentInformation.dtmEnrolled <= #" & dteExpiry & "#;"
- On Error GoTo Err_Execute
- CurrentDb.Execute strSQLAppend, dbFailOnError
- CurrentDb.Execute strSQLDelete, dbFailOnError
- On Error GoTo 0
- Exit Sub
- Err_Execute:
- If DBEngine.Errors.Count > 0 Then
- For Each errLoop In DBEngine.Errors
- MsgBox "Error number: " & errLoop.Number & vbCr & _
- errLoop.Description
- Next errLoop
- End If
- Resume Next
- End Sub
- Private Sub cmdExpiredStudents_Click()
- DoCmd.OpenTable "tblExpiredStudents"
- End Sub
- Private Sub cmdOpenStudentTable_Click()
- DoCmd.OpenTable "tblStudentInformation"
- End Sub
- Private Sub lblClose_Click()
- DoCmd.Close acForm, "frmArchive"
- End Sub
Add new comment
- 44 views