[英]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.