2017-09-26 79 views
0

我試圖在上面的代碼中執行更新語句,但是當執行DoCmd.RunSQL SQL3時,它給出的錯誤爲3265:在此集合中找不到項目。來源:DAO.QueryDefs。 如果有人建議我在這裏丟失什麼,這將是非常好的。3265:在此集合中找不到項目

SQL4 = "SELECT id from tblLastID" 
Set temprsGenerateBilling = CurrentDb().OpenRecordset(SQL4) 
bookingID = temprsGenerateBilling.Fields(0).Value + 1 
SQL3 = "UPDATE tblLastID SET id=" & bookingID 
DoCmd.RunSQL SQL3 

回答

0

使用你已經打開記錄:

SQL4 = "SELECT id from tblLastID" 
Set temprsGenerateBilling = CurrentDb().OpenRecordset(SQL4) 

If temprsGenerateBilling.RecordCount = 0 Then 
    temprsGenerateBilling.AddNew 
Else 
    temprsGenerateBilling.Edit 
End If 
temprsGenerateBilling.Fields(0).Value = Nz(temprsGenerateBilling.Fields(0).Value, 0) + 1 
temprsGenerateBilling.Update 

temprsGenerateBilling.Close 
+0

嗨古斯塔夫。感謝您的建議。當我嘗試執行行temprsGenerateBilling.Fields(0).Value = Nz(temprsGenerateBilling.Fields(0).Value,0)+ 1時出現3027錯誤:無法更新。數據庫或對象是隻讀的。 源:DAO.Field3027:無法更新。數據庫或對象是隻讀的。 來源:DAO.Field –

+0

那麼,你必須理清。如果該表屬於SQL Server,則有很多選項。 – Gustav

+0

是的表屬於sql服務器。如果你提出一條出路,我會非常感激。 –

相關問題