我的代码生成无效的空闲使用,我没有看到问题。当我编译代码时,我没有收到错误,但是当我运行并调试它时,错误发生在strRESMILE = rs(" RESMILE")。
有什么想法?如果需要,我可以上传数据库。
Sub COMPARE()
On Error GoTo err_COMPARE
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim strHold As String
Dim strRESMILE As String
Dim strRESMONTH As String
Dim dblMILEAGEHold As Double
Dim dblDATEHold As Double
Set db = CurrentDb
strSQL = "SELECT * FROM TABLE3"
Set rs = db.OpenRecordset(strSQL)
With rs
' If Not .BOF And Not .EOF Then
' .MoveLast
' .MoveFirst
If Not .BOF Then
strHold = rs("VIN")
dblMILEAGEHold = rs("MILES")
.Edit
rs("RESMILE") = ""
.Update
.MoveNext
'While (Not .EOF)
Do Until .EOF
.Edit
If rs("VIN") = strHold Then
'do comparison
If rs("MILEAGE") > rs("MILES") Then
rs("RESMILE") = "Y"
Else
rs("RESMILE") = "N"
End If
End If
.Update
strHold = rs("VIN")
strRESMILE = rs("RESMILE")
.MoveNext
' Wend
Loop
End If
End With
Set db = CurrentDb
strSQL = "SELECT * FROM TABLE3"
Set rs = db.OpenRecordset(strSQL)
With rs
If Not .BOF Then
strHold = rs("VIN")
dblDATEHold = rs("MONTHS")
.Edit
rs("RESMONTH") = ""
.Update
.MoveNext
Do Until .EOF
.Edit
If rs("VIN") = strHold Then
'do comparison
If rs("INSM") > rs("MONTHS") Then
rs("RESMONTH") = "Y"
Else
rs("RESMONTH") = "N"
End If
End If
.Update
strHold = rs("VIN")
dblDATEHold = rs("RESMONTH")
.MoveNext
Loop
End If
End With
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
MsgBox "Comparisons Completed!"
exit_COMPARE:
Exit Sub
err_COMPARE:
MsgBox Err.Description
Resume exit_COMPARE
End Sub
答案 0 :(得分:1)
使用NULL
处理[RESMILE]
字段中的明显Nz()
。
所以将strRESMILE = rs("RESMILE")
更改为strRESMILE = Nz(rs("RESMILE"))