473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Recordsets and archiving

I want to archive records from one recordset to another recordset. Not too
sure of what to do in commented areas shown below.

Dim Db As DAO.Database
Dim Rec1 As DAO.Recordset 'Set as Global Variables
Dim Rec2 As DAO.Recordset

Public Sub OpenRecSet()
Set Db = CurrentDb()
Set Rec2 = Db.OpenRecordset("Tbl_Archive2004_5", dbOpenDynaset)
Set Rec1 = Db.OpenRecordset("Tbl_Emp", dbOpenDynaset)
End Sub

Private Sub But1_Click()
' Record Set1 is read, one record at a time. If the date in a rec is less
than
' the date on the form, it is to be archived to Tbl_Archive2004_5.

OpenRecSet
Do
If Rec1("Date_of_Job") < Me.ArchDate Then
'Copy Rec1 to Tbl_Archive2004_5

'Delete the record from Tbl_Emp
End If
Rec1.MoveNext
Loop Until Rec1.EOF

Rec1.Close
Rec2.Close

End Sub

Any help will be greatly received
Geoff
Mar 8 '06 #1
4 2409
An append query followed by a delete query would do the same thing quicker.

Running them inside a transaction would be even better.

"Geoff" <gf****@freenetname.co.uk> wrote in message
news:XI******************************@brightview.c om...
I want to archive records from one recordset to another recordset. Not too sure of what to do in commented areas shown below.

Dim Db As DAO.Database
Dim Rec1 As DAO.Recordset 'Set as Global Variables
Dim Rec2 As DAO.Recordset

Public Sub OpenRecSet()
Set Db = CurrentDb()
Set Rec2 = Db.OpenRecordset("Tbl_Archive2004_5", dbOpenDynaset)
Set Rec1 = Db.OpenRecordset("Tbl_Emp", dbOpenDynaset)
End Sub

Private Sub But1_Click()
' Record Set1 is read, one record at a time. If the date in a rec is less
than
' the date on the form, it is to be archived to Tbl_Archive2004_5.

OpenRecSet
Do
If Rec1("Date_of_Job") < Me.ArchDate Then
'Copy Rec1 to Tbl_Archive2004_5

'Delete the record from Tbl_Emp
End If
Rec1.MoveNext
Loop Until Rec1.EOF

Rec1.Close
Rec2.Close

End Sub

Any help will be greatly received
Geoff

Mar 8 '06 #2
I would probably do this in a transaction. One query to copy the records,
another to delete them. That way, if anything goes wrong it all get rolled
back. No 'half-done' problem.

Dim strQ as String
Dim wrkMyWS as DAO.Workspace
Dim dbMyDB as DAO.Database

Set wrkMyWS = DBEngine.Workspaces(0)
Set dbMyDB = CurrentDB()

wrkMyWS.BeginTrans

strQ = <Append SQL Statement to copy>
dbMyDB.Execute strQ
strQ = <SQL Statement to delete>
dbMyDB.Execute strQ

wrkMyWS.CommitTrans

dbMyDB.Close
Set dbMyDB = Nothing
Set wrkMyWS = Nothing

This is air code and would obviously need error trapping etc.

Jeff Pritchard
________________
Asken Research Pty. Ltd.
Access Database Developers
http://www.asken.com.au

"Geoff" <gf****@freenetname.co.uk> wrote in message
news:XI******************************@brightview.c om...
I want to archive records from one recordset to another recordset. Not too
sure of what to do in commented areas shown below.

Dim Db As DAO.Database
Dim Rec1 As DAO.Recordset 'Set as Global Variables
Dim Rec2 As DAO.Recordset

Public Sub OpenRecSet()
Set Db = CurrentDb()
Set Rec2 = Db.OpenRecordset("Tbl_Archive2004_5", dbOpenDynaset)
Set Rec1 = Db.OpenRecordset("Tbl_Emp", dbOpenDynaset)
End Sub

Private Sub But1_Click()
' Record Set1 is read, one record at a time. If the date in a rec is less
than
' the date on the form, it is to be archived to Tbl_Archive2004_5.

OpenRecSet
Do
If Rec1("Date_of_Job") < Me.ArchDate Then
'Copy Rec1 to Tbl_Archive2004_5

'Delete the record from Tbl_Emp
End If
Rec1.MoveNext
Loop Until Rec1.EOF

Rec1.Close
Rec2.Close

End Sub

Any help will be greatly received
Geoff

Mar 8 '06 #3

"Geoff" <gf****@freenetname.co.uk> wrote in message
news:XI******************************@brightview.c om...
I want to archive records from one recordset to another recordset. Not too
sure of what to do in commented areas shown below.

Dim Db As DAO.Database
Dim Rec1 As DAO.Recordset 'Set as Global Variables
Dim Rec2 As DAO.Recordset

Public Sub OpenRecSet()
Set Db = CurrentDb()
Set Rec2 = Db.OpenRecordset("Tbl_Archive2004_5", dbOpenDynaset)
Set Rec1 = Db.OpenRecordset("Tbl_Emp", dbOpenDynaset)
End Sub

Private Sub But1_Click()
' Record Set1 is read, one record at a time. If the date in a rec is less
than
' the date on the form, it is to be archived to Tbl_Archive2004_5.

OpenRecSet
Do
If Rec1("Date_of_Job") < Me.ArchDate Then
'Copy Rec1 to Tbl_Archive2004_5

'Delete the record from Tbl_Emp
End If
Rec1.MoveNext
Loop Until Rec1.EOF

Rec1.Close
Rec2.Close

End Sub

Any help will be greatly received
Geoff


As your other two replies point out, transactions are the way forward. In
this version, I add records to one table and then delete them from the
first - if the two counts match, I commit the transaction.
What nobody has yet commented on is whther you really need to archive.
According to my statistics, the average Access Developer uses archiving
73.2% more often than is really required. In other words, are you really
sure you need to move the data to another table? What improvements (in
speed or otherwise) do you think you will achieve? What steps have you
taken to show this increase in speed (efficiency or whatever) before you go
ahead and implement the archiving routine?
Public Sub DoArchive()

On Error GoTo Err_Handler

Dim lngRecCount As Long

lngRecCount = ArchiveRecords("Tbl_Emp", "Tbl_Archive2004_5",
DateSerial(2006, 3, 8))

MsgBox CStr(lngRecCount) & " record(s) archived", _
vbInformation, "Archive Routine"

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub
Public Function ArchiveRecords(SourceTable As String, _
TargetTable As String, _
StartDate As Date) As Long

On Error GoTo Err_Handler

Dim wks As DAO.Workspace
Dim dbs As DAO.Database
Dim dteDate As Date
Dim strSQL As String
Dim lngAdded As Long
Dim lngDeleted As Long

dteDate = DateSerial(Year(StartDate), _
Month(StartDate), _
Day(StartDate))

dteDate = DateAdd("d", 1, dteDate)

Set wks = DBEngine.Workspaces(0)

wks.BeginTrans

Set dbs = wks.Databases(0)

strSQL = "INSERT INTO " & TargetTable & _
" SELECT * FROM " & SourceTable & _
" WHERE ComDate<#" & _
Format(dteDate, "yyyy-mm-dd") & "#"

dbs.Execute strSQL, dbFailOnError

lngAdded = dbs.RecordsAffected

strSQL = "DELETE FROM " & SourceTable & _
" WHERE ComDate<#" & _
Format(dteDate, "yyyy-mm-dd") & "#"

dbs.Execute strSQL, dbFailOnError

lngDeleted = dbs.RecordsAffected

If lngAdded = lngDeleted Then
wks.CommitTrans
ArchiveRecords = lngAdded
Else
wks.Rollback
End If

Exit_Handler:

If Not dbs Is Nothing Then
Set dbs = Nothing
End If

If Not wks Is Nothing Then
Set wks = Nothing
End If

Exit Function

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Function
Mar 8 '06 #4
"Anthony England" <ae******@oops.co.uk> wrote in
news:du**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com:
What nobody has yet commented on is whther you really need to
archive. According to my statistics, the average Access Developer
uses archiving 73.2% more often than is really required.


I never archive active data. Period.

The only thing I do archive is certain datasets that are constructed
for exporting, so that it's possible to go back and reconstruct
exactly what was exported. That's a very different kind of thing,
because there you're exporting a snapshot of a subset of data at a
particular time, and if you need to know what that included, you
have to archive it.

I'd never archive data just to clear old data out of active data
tables. I'd simply filter the results given to users according to a
rolling window calculated based on the current date. This would then
allow the user to see the historical data and do operations on the
full data set, going back as far as they liked.

And it doesn't slow things down significantly at all, if you've
properly normalized your data structure and applied appropriate
indexing.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Mar 9 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: tim groulx | last post by:
Hello, Does anyone know of a way to schedule the archiving of analysis databases? Seems pretty lame if you can't... The only answer I've gotten is "maybe in Yukon".... Thanks.
5
by: SunSmile | last post by:
Hi, I am logging my exceptions to a word document(*.doc). After the size of word document is 5KB. I am archiving the word document to *.doc.1 Here when I am archiving the word document to...
16
by: Randy Harris | last post by:
I was inspired by the recent discussion of returning multiple recordsets to ADO from a stored procedure. (Amazed is probably more accurate). I asked about how to accomplish same with Oracle and...
5
by: pike | last post by:
Hi Single partition DB2v8.1 FP7 on AIX 5.2. I'm trying to determine whether we're archiving logs directly to tape (and not to disk) using TSM. Without knowing from which sample it was...
1
by: sandip | last post by:
Hi All, Can someone please help me with good and easy-to-use data archiving tools for DB2 database? Does anyone have previous experience with IBM DB2 Data Archive Expert tool? Is this a...
4
by: Paul H | last post by:
Could some one give me some pointers on basic archiving techniques? I have developed several databases but never been faced with this issue. Here is the basic scenario.. Suppose I have the...
2
by: Knokmans | last post by:
Hi, first, this concerns db2 v8 and v9 on AIX and Linux/intel Until now we used a "user exit" when we want to archive logfiles. We changed the user exit executable a bit so we receive an email...
3
bvdet
by: bvdet | last post by:
Following is an example that may provide a solution to you: """ Function makeArchive is a wrapper for the Python class zipfile.ZipFile 'fileList' is a list of file names - full path each name...
6
by: Salad | last post by:
I'm going to implement an archival database for my app. I have Table1 and Table2. Table2 is a duplicate structure of Table1. I appended records with "ID between 1 and 100", then "ID between 300...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.