我创建了一个附加了子表单的表单。我有一个按钮,它运行一个查询来删除记录,但首先我要复制数据,包括所有子表单信息(如果可用)。我使用了以下代码但没有任何反应。请!我错过了什么?
Private Sub Command63_Click()
Dim db As Database, delfile As Recordset, Criteria As String
Set db = CurrentDb
Set delfile = db.OpenRecordset("DelFile", DB_OPEN_DYNASET)
'add data to deleted taxpayer file table
With delfile
.AddNew
!DeletedBy = (Forms!MainMenu!username)
!Branch = Me.Branch
!TaxType = Me.TaxType
!Volume = Me.Volume
!Keyedby = Me.Keyedby
!DateKeyed = Me.DateKeyed
!CreatedAt = Me.CreatedAt
!Comment = Me.Comment
End With
delfile.Close
db.Close
End Sub
答案 0 :(得分:1)
设置完所有字段值后,您需要添加.update
才能使更改生效。你的新代码看起来像这样。
Private Sub Command63_Click()
Dim db As Database, delfile As Recordset, Criteria As String
Set db = CurrentDb
Set delfile = db.OpenRecordset("DelFile", DB_OPEN_DYNASET)
'add data to deleted taxpayer file table
With delfile
.AddNew
!DeletedBy = (Forms!MainMenu!username)
!Branch = Me.Branch
!TaxType = Me.TaxType
!Volume = Me.Volume
!Keyedby = Me.Keyedby
!DateKeyed = Me.DateKeyed
!CreatedAt = Me.CreatedAt
!Comment = Me.Comment
.Update
End With
delfile.Close
db.Close
End Sub