R
Roxana
Hello,
I am working with an Access 2007 application.
I have this code that writes records in a table. The code runs ok but it
takes too long. For one month of data it takes about 40 min but if I add the
second month it takes more than an hour.
I have a form with a button. When click on the button I want to read a table
with over 300,000 recs/month, join with 2 other tables (one of them with
about 100,000 recs), perform some calculations and write data into a history
table. For each month I would have about 100,000 recs to add to the history
table. I would like to keep at least 2 months of data in the history table.
My code in VB is something like this:
I have a routine that reads the fields from a Balance table, groups data by
cust_id and does some calculations
Private Sub cmdRead_Click()
Set MyDb = CurrentDb
SSQL = "SELECT * FROM tbl_Balances where CUST_ID > '0' order by CUST_ID"
Set myRS = MyDb.OpenRecordset(SSQL)
With myRS
..MoveFirst
While myRS.EOF = False
Calculations
Call Update_History(process_year, process_month, CustID, Amount)
MoveNext
Wend
EndWith
This is the function that writes the data in the History table:
Public Function Update_History(hyear As String, hmonth As String, cust_id As
String, balance As Double)
Dim urs As Recordset
Set urs = MyDb.OpenRecordset("Select * from TblHistory")
urs.AddNew
urs.Fields(0) = hyear
urs.Fields(1) = hmonth
urs.Fields(2) = cust_id
urs.Fields(3) = balance
urs.Update
urs.Close
End Function
Would there be a better way of doing this and speed things up ?
Any sugestion would be appreciated.
Thank you.
I am working with an Access 2007 application.
I have this code that writes records in a table. The code runs ok but it
takes too long. For one month of data it takes about 40 min but if I add the
second month it takes more than an hour.
I have a form with a button. When click on the button I want to read a table
with over 300,000 recs/month, join with 2 other tables (one of them with
about 100,000 recs), perform some calculations and write data into a history
table. For each month I would have about 100,000 recs to add to the history
table. I would like to keep at least 2 months of data in the history table.
My code in VB is something like this:
I have a routine that reads the fields from a Balance table, groups data by
cust_id and does some calculations
Private Sub cmdRead_Click()
Set MyDb = CurrentDb
SSQL = "SELECT * FROM tbl_Balances where CUST_ID > '0' order by CUST_ID"
Set myRS = MyDb.OpenRecordset(SSQL)
With myRS
..MoveFirst
While myRS.EOF = False
Calculations
Call Update_History(process_year, process_month, CustID, Amount)
MoveNext
Wend
EndWith
This is the function that writes the data in the History table:
Public Function Update_History(hyear As String, hmonth As String, cust_id As
String, balance As Double)
Dim urs As Recordset
Set urs = MyDb.OpenRecordset("Select * from TblHistory")
urs.AddNew
urs.Fields(0) = hyear
urs.Fields(1) = hmonth
urs.Fields(2) = cust_id
urs.Fields(3) = balance
urs.Update
urs.Close
End Function
Would there be a better way of doing this and speed things up ?
Any sugestion would be appreciated.
Thank you.