如何在ms访问中将数据从表单+子表单复制到表?

时间:2014-01-24 19:09:38

标签: forms ms-access insert-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 
End With 
delfile.Close 
db.Close 
End Sub

1 个答案:

答案 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