简体   繁体   English

MS Access:如果我只想将我更改/修改的记录插入到新表中,我的 Insert Into Statement 应该是什么样子?

[英]MS Access: How does my Insert Into Statement has to look like if i want to insert only the record i changed/modified into a new table?

I have a continues form where the user can edit data, stored in the table, directly.我有一个连续表单,用户可以在其中直接编辑存储在表中的数据。 Before the user can close the form or edit a different record he is asked if he wants to save his changes.在用户可以关闭表单或编辑不同的记录之前,系统会询问他是否要保存他的更改。 I use the Before Update Event for that:为此,我使用更新前事件:

Private Sub Form_BeforeUpdate(Cancel As Integer)
'Msg Box Nachricht bestimmen.
    strMsg = "M?chten Sie die ?nderungen speichern?" & Chr(10)
    strMsg = strMsg & "Dr?cken Sie Ja um zu speichern oder Nein um die ?nderungen zu verwerfen."

    'Msg Box anzeigen.
    iResponse = MsgBox(strMsg, vbQuestion + vbYesNo, "Speichern?")

    'Nutzer Antwort pruefen
    If iResponse = vbNo Then

        'Aenderungen verwerfen.
         Me.Undo
        'Update abbrechen.
         Cancel = True
    End If
End Sub

When the form loads i get the current value of the text field by using this:加载表单时,我使用以下方法获取文本字段的当前值:

Private Sub Form_Load()
TempVars("Status") = txtStatus.Value
End Sub

Now if the User changes this text field the record (with the old value for txtStatus) should be saved in a new table.现在,如果用户更改此文本字段,记录(txtStatus 的旧值)应保存在新表中。 This code WITHOUT the "Where"-Part copies all the records in my table, into the new table:此代码没有“Where”-Part 将我表中的所有记录复制到新表中:

Dim Status As String
Dim Counter As Integer
Counter = 0

If txtStatus.Value <> TempVars("getStatus") Then
Status = txtStatus.Value
Counter = Counter + 1
End If

Dim sql As String
Dim dbs As DAO.Database
Set dbs = CurrentDb()

    sql = "Insert into tblStatusFahrzeugeHistory (F_ID, Status, seit, bis, von, an, Bemerkung, Datenbank_Nutzer, Eintrag_erstellt_am, Eintrag_erstellt_um)" & _
"Select tblStatusFahrzeuge.F_ID, tblStatusFahrzeuge.Status, tblStatusFahrzeuge.seit, tblStatusFahrzeuge.bis, tblStatusFahrzeuge.von, tblStatusFahrzeuge.an, tblStatusFahrzeuge.Bemerkung, tblStatusFahrzeuge.Datenbank_Nutzer, tblStatusFahrzeuge.Eintrag_erstellt_am, tblStatusFahrzeuge.Eintrag_erstellt_um " & _
"From tblStatusFahrzeuge Where txtStatus.Value = Status "

dbs.Execute sql, dbFailOnError
dbs.Close
Set dbs = Nothing
    End If

WITH the "Where"-Part i attempted to insert only the record i changed on the form into the new table but the code does'nt work.对于“Where”部分,我试图仅将我在表单上更改的记录插入到新表中,但代码不起作用。 I get this error code: runtime error'3061' 1 parameters were expected, but too few parameters were passed.Does someone know what im doing wrong?我收到此错误代码:运行时错误“3061”需要 1 个参数,但传递的参数太少。有人知道我做错了什么吗?

The query engine cannot "see" txtStatus.Value.查询引擎无法“看到”txtStatus.Value。 You will either have to add parameters to your query, or concatenate in the value of the text box into the query text:-您要么必须向查询添加参数,要么将文本框的值连接到查询文本中:-

    sql = "Insert into tblStatusFahrzeugeHistory (F_ID, Status, seit, bis, von, an, Bemerkung, Datenbank_Nutzer, Eintrag_erstellt_am, Eintrag_erstellt_um)" & _
"Select tblStatusFahrzeuge.F_ID, tblStatusFahrzeuge.Status, tblStatusFahrzeuge.seit, tblStatusFahrzeuge.bis, tblStatusFahrzeuge.von, tblStatusFahrzeuge.an, tblStatusFahrzeuge.Bemerkung, tblStatusFahrzeuge.Datenbank_Nutzer, tblStatusFahrzeuge.Eintrag_erstellt_am, tblStatusFahrzeuge.Eintrag_erstellt_um " & _
"From tblStatusFahrzeuge Where '" & txtStatus.Value & "' = Status "

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在此表中插入新记录? - How do i insert new record in this table? 如果不存在值(仅针对某些条件),如何将其插入表中? (MS SQL Server) - How do I insert into a table if a value does not exist, but only for certain criteria? (MS SQL Server) 如果记录不存在,我怎么才能插入记录? - How can I only insert a record if it does not exists? 如何将数据插入VB.net中的2个不同表中,我正在使用MS Access作为数据库 - How can I insert data into 2 different table in VB.net, I'm using MS Access as my db 基于sql我有一个如下表我想在我想删除记录的地方插入一条记录? - based on sql i had a table as below i want to insert a record where i want to delete a record? 现在我想通过 MS Access Query 从我的 Transection 表中为每个客户生成 Ledger 语句 - Now I want to generate Ledger statement for each client from my Transection Table through MS Access Query 如何将基于行的上一个和下一个记录数据插入到 MS Access 时间序列数据中? - How can I insert rows based previous and next record data into MS Access time sequenced data? 如何将 Update 语句添加到我即将使用 MS SQL 查询插入到表中的选定行? - How do I add Update statement to selected rows I am about to insert into a table with MS SQL query? 如何在mysql中具有外键属性的表中插入新记录 - how to insert a new record in a table that has foreign key attributes in mysql MS Access SQL复制在窗体上显示的记录的一部分,插入到与新记录相同的表中,并在窗体上显示新记录 - MS Access SQL to copy part of a record displayed on a form, insert into same table as new record, and display the new record on a form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM