标题: 请大家来帮帮忙:利用recordset.find更新记录时出现的问题 [打印本页] 作者: effytears 时间: 2008-12-1 20:04 标题: 请大家来帮帮忙:利用recordset.find更新记录时出现的问题 小弟我 刚学ACCESS不久,对代码也不算了解,写了如下代码,总是不理想,请各位高手帮帮忙, 谢谢啦
Dim rst1 As ADODB.Recordset
Dim rst2 As ADODB.Recordset
Set rst1 = New ADODB.Recordset
Set rst2 = New ADODB.Recordset
Dim str1, str2 As String
str1 = "select tblorder.partinfoID,sum(tblorder.partsum) as totalsum from tblorder "
str1 = str1 + "group by tblorder.partinfoID"
With rst1
.ActiveConnection = CurrentProject.Connection
.CursorType = adOpenForwardOnly
.LockType = adLockReadOnly
.Open str1, options:=adCmdText
End With
str2 = "select totalparts.partinfoID,totalparts.partsum from totalparts "
With rst2
.ActiveConnection = CurrentProject.Connection
.CursorType = adOpenDynamic
.LockType = adLockPessimistic
.Open str2, options:=adCmdText
End With
Do Until rst1.EOF
rst2.Find "[partinfoID]=" & rst1!partinfoID
If rst2.EOF Then
With rst2
.AddNew
!partinfoID = rst1!partinfoID
!partsum = rst1!totalsum
.Update
End With
Else
rst2!partsum = rst1!totalsum
End If
rst1.MoveNext
Loop
rst1.Close
rst2.Close
Set rst1 = Nothing
Set rst2 = Nothing