2016-02-13 71 views
0

我想在按下按鈕時更新並在同一個表中插入記錄。VBA訪問更新同一表的多條記錄

1st。我將「NoLot」更新爲「0」,其中noSoumisson = X

2nd。我想用新的NoSoumission在同一張表上插入/複製新記錄。

只有當我嘗試將NoLot更改爲「0」時纔會出現寫入錯誤衝突。

爲什麼?我想用新字段對記錄進行復制/修訂,同時我想從上一條記錄中刪除另一個字段。

Dim strNoLot As String 
    Dim strSQLNoLotDelete As String 

    strNoLot = DLookup("tblSoumissionDetails.[NoLot]", "tblSoumissionDetails", "_ 
    & "tblSoumissionDetails.NoSoumission= '" & Me.NoSoumission & "'") 

    strSQLNoLotDelete = "UPDATE tblSoumissionDetails " _ 
    & " SET tblSoumissionDetails.NoLot = '0' " _ 
    & " WHERE tblSoumissionDetails.NoSoumission= '" & Me.NoSoumission & "'" 

    DoCmd.RunSQL strSQLNoLotDelete 

THEN ....在同一個SUB!內!

Dim strSQLCopie As String 

    strSQLCopie = "INSERT INTO tblSoumissionDetails (NoSoumission, NoLot, IDListe, " _ 
    & "Createur, IDEmploye, [no client], [nom liste], [date], [no contact]) " _ 
    & " SELECT '" & strNumeroAutoRev & "' AS NoSoumission, '" & strNoLot & "' " _ 
    & " AS NoLot, tblSoumissionDetails.IDListe, '" & strUsername & "' , " _ 
    & " tblSoumissionDetails.IDEmploye, " _ 
    & " tblSoumissionDetails.[no client] , tblSoumissionDetails.[nom liste], " _ 
    & "'" & date & "' , tblSoumissionDetails.[no contact] " _ 
    & " From tblSoumissionEncours, tblSoumissionDetails " _ 
    & " WHERE (((tblSoumissionDetails.NoSoumission)= '" & Me.NoSoumission & "'));" 

    DoCmd.RunSQL strSQLCopie 
+2

什麼是你的問題?什麼是錯誤? – Parfait

回答

0

很好地解決加入這個我的問題......

Me.Dirty = False