我试图将日期的值重置为null,将体重的值重置为null。
我尝试了以下代码,但只有体重被设置为0,日期未被设置为null:
我尝试了以下代码,但只有体重被设置为0,日期未被设置为null:
Private Sub Form_Load()
Me.Text42.Value = ""
Dim i As Integer
Dim Db6 As Database
Dim Rs6 As Recordset
Dim Trn6 As String
Set Db6 = CurrentDb
Set Rs6 = Db6.OpenRecordset("GoatMasterTable")
Do While Not Rs6.EOF
If Rs6.Fields("Recentweight") > 0 Then
Rs6.Edit
Rs6.Fields("RecentWeight") = 0
Rs6.Fields("RecentWeightDate") = """" Or IsNull(Rs6!RecentWeightDate)
Rs6.Update
End If
Rs6.MoveNext
Loop
Rs6.Close
Set Rs6 = Nothing
Db6.Close
End Sub
db.Close
!你想要的是Set db = Nothing
,但这在这里并不是必要的(但也不会有太大的影响),因为VBA计算实例的对象引用,并且如果它们超出范围,就会销毁它们。第三:使用@LeeMacs的答案! - ComputerVersteher