什么叫 '单条数据更新' DAO 一样可以同时更新多条记录呀.Sub UpdateX() Dim dbsNorthwind As Database Dim rstEmployees As Recordset Dim strOldFirst As String Dim strOldLast As String Dim strMessage As String Set dbsNorthwind = OpenDatabase("Northwind.mdb") Set rstEmployees = _ dbsNorthwind.OpenRecordset("Employees") With rstEmployees .Edit ' Store original data. strOldFirst = !FirstName strOldLast = !LastName ' Change data in edit buffer. !FirstName = "Linda" !LastName = "Kobara" ' Show contents of buffer and get user input. strMessage = "Edit in progress:" & vbCr & _ " Original data = " & strOldFirst & " " & _ strOldLast & vbCr & " Data in buffer = " & _ !FirstName & " " & !LastName & vbCr & vbCr & _ "Use Update to replace the original data with " & _ "the buffered data in the Recordset?" If MsgBox(strMessage, vbYesNo) = vbYes Then .Update Else .CancelUpdate End If ' Show the resulting data. MsgBox "Data in recordset = " & !FirstName & " " & _ !LastName ' Restore original data because this is a demonstration. If Not (strOldFirst = !FirstName And _ strOldLast = !LastName) Then .Edit !FirstName = strOldFirst !LastName = strOldLast .Update End If .Close End With dbsNorthwind.CloseEnd Sub
updatebatch方法
或者用标准SQL语句的UPDATE更新方法
DAO 一样可以同时更新多条记录呀.Sub UpdateX() Dim dbsNorthwind As Database
Dim rstEmployees As Recordset
Dim strOldFirst As String
Dim strOldLast As String
Dim strMessage As String Set dbsNorthwind = OpenDatabase("Northwind.mdb")
Set rstEmployees = _
dbsNorthwind.OpenRecordset("Employees") With rstEmployees
.Edit
' Store original data.
strOldFirst = !FirstName
strOldLast = !LastName
' Change data in edit buffer.
!FirstName = "Linda"
!LastName = "Kobara" ' Show contents of buffer and get user input.
strMessage = "Edit in progress:" & vbCr & _
" Original data = " & strOldFirst & " " & _
strOldLast & vbCr & " Data in buffer = " & _
!FirstName & " " & !LastName & vbCr & vbCr & _
"Use Update to replace the original data with " & _
"the buffered data in the Recordset?" If MsgBox(strMessage, vbYesNo) = vbYes Then
.Update
Else
.CancelUpdate
End If ' Show the resulting data.
MsgBox "Data in recordset = " & !FirstName & " " & _
!LastName ' Restore original data because this is a demonstration.
If Not (strOldFirst = !FirstName And _
strOldLast = !LastName) Then
.Edit
!FirstName = strOldFirst
!LastName = strOldLast
.Update
End If .Close
End With dbsNorthwind.CloseEnd Sub