|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi All,
I need to do housekeep in a table based on the following condition Condition: If the first record is before 2 yrs, then the cascading records whether 2 yrs or created yesterday should get deleted. I created a module for this, pls correct me if myself done any wrong. Dim tempdate As Date Dim curdate As Date Dim db As DAO.Database Dim rst As DAO.Recordset Dim tbl As DAO.Recordset curdate = Date db = CurrentDb() tempdate = DateAdd("YYYY", -2, curdate) rst = db.OpenRecordset("select nric from offender where [date recorded] = '#tempdate#'") Do While rst.EOF = False tbl = db.OpenRecordset("select * from offender where nric = rst(0)") tbl.Delete rst.MoveNext Loop Thanks in advance Raj ![]() Last edited by rajkumar : September 3rd, 2003 at 01:52 AM. |
|
#2
|
|||
|
|||
|
You can use an action query to execute the delete in one swoop:
Code:
Dim tempdate As Date
Dim curdate As Date
Dim db As DAO.Database
curdate = Date
db = CurrentDb()
tempdate = DateAdd("YYYY", -2, curdate)
db.Execute ("DELETE FROM offender WHERE " & _
" [date recorded] = '#tempdate#'")
In this case you do not need to create 2 recordsets which uses a lot of overhead. Hope this helps
__________________
- Rogier Doekes |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft SQL Server > Housekeep table - Very Urgent |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|