我的任务是修改一个字段" TimeAfterClass" (双)产生一个新领域" NewTimeAfterClass" (也是双倍)包含唯一数字。我创建了一个按钮来完成此任务并且它不会产生任何错误,但它也不会更新NewTimeAfterClass字段,当我将鼠标悬停在[TimeAfterClass]上时,它显示为Empty。有关为什么会发生这种情况的任何建议吗?这是代码:
Private Sub Command0_Click()
Dim CurrentTimeAfterClass As Double
Dim NewTimeAfterClass As Double
Dim strSQL As String
Dim increment As Double
increment = 0.01
'Dim db As DAO.Database
Dim rs As ADODB.Recordset
'Set db = CurrentDb
Set rs = New ADODB.Recordset
With rs
.Open "Scores", CurrentProject.Connection, adOpenDynamic, adLockBatchOptimistic
.MoveFirst
While Not .EOF
CurrentTimeAfterClass = [TimeAfterClass]
CurrentIncrement = 0
CurrentIncrement = increment
NewTimeAfterClass = CurrentTimeAfterClass + CurrentIncrement
If CurrentIncrement > 0 Then
CurrentIncrement = CurrentIncrement * (-1)
Else
CurrentIncrement = CurrentIncrement * (-1) + increment
End If
.Update
.MoveNext
Wend
End With
rs.Close
Set rs = Nothing
End Sub
答案 0 :(得分:0)
不确定您尝试使用增量做什么,所以我只能假设您知道自己在做什么。
要使更新工作尝试此操作 - 可能在备份db ??
Private Sub Command0_Click()
Dim CurrentTimeAfterClass As Double
' You don't need this if you're updating the field directly
'Dim NewTimeAfterClass As Double
Dim strSQL As String
Dim increment As Double
increment = 0.01
'Dim db As DAO.Database
Dim rs As ADODB.Recordset
'Set db = CurrentDb
Set rs = New ADODB.Recordset
With rs
.Open "Scores", CurrentProject.Connection, adOpenDynamic, adLockBatchOptimistic
.MoveFirst
While Not .EOF
CurrentTimeAfterClass = !TimeAfterClass
CurrentIncrement = 0
CurrentIncrement = increment
!NewTimeAfterClass = CurrentTimeAfterClass + CurrentIncrement
If CurrentIncrement > 0 Then
CurrentIncrement = CurrentIncrement * (-1)
Else
CurrentIncrement = CurrentIncrement * (-1) + increment
End If
.Update
.MoveNext
Wend
End With
rs.Close
Set rs = Nothing
End Sub