Year-wise Database

gear

Registered User.
Local time
Today, 11:18
Joined
Mar 10, 2007
Messages
112
After looking at the replies to my post on the above subject, I realize that one needs to be an expert programmer in VB, SQL etc. to design queries/forms to filter records year-wise for all type of record operations. I know nothing about programming. So I have used these codes (of course, with the help of this forum) :

Private Sub Form_BeforeInsert(Cancel As Integer)
If IsNull(Me![DyNo]) Then
Me![DyNo] = Format(Nz(DMax("[DyNo]", "[tblAllDet]", "[TheYear]='" & Year(Date) & "'"), 0) + 1, "0")
End If
Me![DyNo] = Format([DyNo], "0")

If DatePart("m", Now()) = 1 And [DyNo] = 1 Then

Backup

Dim db As Database, rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tblAllDet")

db.Execute "DELETE * FROM [tblAllDet];"
rs.Close
db.Close

Else
End If

End Sub

First, with DMax, my DyNo field is reset to No.1 on change of year.
Then, ‘DatePart’ code looks for January and DyNo.1 and does Backup (a module) of existing records.
Lastly, all records in the current DB is deleted so I get a blank database for the new year.

For the previous year’s records, I can rename the backup file year-wise and use.

I have tested this with dummy records and changing system date. I didn’t face any problem. However, I would like the experts of this forum to have a look at the above codes and point out any flaws. Thanks in advance.
 
Why bother removing a years data? If the records are dated there's no need.

Also, you won't be able to do year-on-year comparisons so easily.

Col
 

Users who are viewing this thread

Back
Top Bottom