2014-01-24 53 views
0

我創建了一個附有子窗體的窗體。我有一個運行查詢來刪除記錄的按鈕,但首先我想複製包含所有子窗體信息(如果可用的話)的數據。我使用了下面的代碼,但沒有任何反應。請!我錯過了什麼?如何將數據從表單+子表單複製到ms訪問表中?

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

設置了所有字段值後,需要包含.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 
+0

我在代碼中添加了.Update,但我現在收到錯誤。 btw表單Im將數據從一個表中綁定到另一個表中,是否會導致問題? – Kefash

+0

我剛纔看到了我的錯誤。以及丟失的.update行,我正在從我發送信息的表格中刪除必填字段。 – Kefash

相關問題