I am bumping a rather large recordset (8000 + records) to find records in another table using DAO. What I have set up will take 30 hours to run. I think there has to be a better way.
<code>
Set rsSource = db.OpenRecordset("SELECT TNResidentsTest.*" _
& " FROM TNResidentsTest" _
& " ORDER BY TNResidentsTest.GPGROUP;", dbOpenSnapshot)
If rsSource.EOF = True And rsSource.BOF = True Then
'close objects in reverse order to release variable
rsSource.Close
Set rsSource = Nothing
Set rsAdd = Nothing
Set db = Nothing
Set tdf = Nothing
Exit Function
End If
'open recordset for add
Set rsAdd = db.OpenRecordset("SELECT [TNResidentClaimNumbers].*" _
& " FROM [TNResidentClaimNumbers];")
Do Until rsSource.EOF = True
'set start time
varStartTime2 = Timer
Select Case Trim(rsSource!GPGROUP)
Case "30"
'get claims from specific claims table
Set rsGrpClms = db.OpenRecordset("SELECT SMARTHEALTH.CLYEAR, SMARTHEALTH.CLMONTH, SMARTHEALTH.CLDAY, SMARTHEALTH.CLACLMNO" _
& " FROM SMARTHEALTH" _
& " WHERE (((SMARTHEALTH.CLPARTIC)= " & "'" & rsSource!GPPARTIC & "'));", dbOpenDynaset)
If rsGrpClms.EOF = False And rsGrpClms.BOF = False Then
Do Until rsGrpClms.EOF = True
With rsAdd
.AddNew
!CLGROUP = Trim(rsSource!GPGROUP)
!CLPARTIC = Trim(rsSource!GPPARTIC)
!CLYEAR = Trim(rsGrpClms!CLYEAR)
!CLMONTH = Trim(rsGrpClms!CLMONTH)
!CLDAY = Trim(rsGrpClms!CLDAY)
!CLACLMNO = Trim(rsGrpClms!CLACLMNO)
.Update
End With
rsGrpClms.MoveNext
Loop
End If
<code>
The slow down is the query to the SMARTHEALTH table which has almost 1 million records and the return is so slow that it takes about 2 minutes to process each row from TNResidents. I can create a snapshot of the entire SMARTHEALTH table in less than 2 seconds but do not know how to extract the information. I have looked at SEEK and FindFirst but they are not as efficient as I'd like. Any suggestions will be appreciated.
Thanks.
Joel
<code>
Set rsSource = db.OpenRecordset("SELECT TNResidentsTest.*" _
& " FROM TNResidentsTest" _
& " ORDER BY TNResidentsTest.GPGROUP;", dbOpenSnapshot)
If rsSource.EOF = True And rsSource.BOF = True Then
'close objects in reverse order to release variable
rsSource.Close
Set rsSource = Nothing
Set rsAdd = Nothing
Set db = Nothing
Set tdf = Nothing
Exit Function
End If
'open recordset for add
Set rsAdd = db.OpenRecordset("SELECT [TNResidentClaimNumbers].*" _
& " FROM [TNResidentClaimNumbers];")
Do Until rsSource.EOF = True
'set start time
varStartTime2 = Timer
Select Case Trim(rsSource!GPGROUP)
Case "30"
'get claims from specific claims table
Set rsGrpClms = db.OpenRecordset("SELECT SMARTHEALTH.CLYEAR, SMARTHEALTH.CLMONTH, SMARTHEALTH.CLDAY, SMARTHEALTH.CLACLMNO" _
& " FROM SMARTHEALTH" _
& " WHERE (((SMARTHEALTH.CLPARTIC)= " & "'" & rsSource!GPPARTIC & "'));", dbOpenDynaset)
If rsGrpClms.EOF = False And rsGrpClms.BOF = False Then
Do Until rsGrpClms.EOF = True
With rsAdd
.AddNew
!CLGROUP = Trim(rsSource!GPGROUP)
!CLPARTIC = Trim(rsSource!GPPARTIC)
!CLYEAR = Trim(rsGrpClms!CLYEAR)
!CLMONTH = Trim(rsGrpClms!CLMONTH)
!CLDAY = Trim(rsGrpClms!CLDAY)
!CLACLMNO = Trim(rsGrpClms!CLACLMNO)
.Update
End With
rsGrpClms.MoveNext
Loop
End If
<code>
The slow down is the query to the SMARTHEALTH table which has almost 1 million records and the return is so slow that it takes about 2 minutes to process each row from TNResidents. I can create a snapshot of the entire SMARTHEALTH table in less than 2 seconds but do not know how to extract the information. I have looked at SEEK and FindFirst but they are not as efficient as I'd like. Any suggestions will be appreciated.
Thanks.
Joel