我有一个通过表单生成的表,然后这些数据会过滤到另一个表单。然后勾选第二个表单,我需要将人员窗口ID拉到表中以完成记录集。我一直在附加表,但记录都出现在当前保存的数据之后。有没有办法附加到保存的记录,标识字段是DateCompleted和ClientID。 附加我想要的表的SQL,尽管在记录之后是 -
INSERT INTO ChecklistResults ( ManagerID )
SELECT ChecklistResults.ManagerID
FROM ChecklistResults
WHERE (((ChecklistResults.ClientID)=[Forms]![TeamLeader]![ComClientNotFin]) AND ((ChecklistResults.DateCompleted)=[Forms]![TeamLeader]![ComDateSelect]));
有没有办法直接追加记录中的空白(ManagerID)字段或完全重写当前记录?
答案 0 :(得分:0)
我找到了解决问题的方法。我有一个表缺少一个字段,所以我创建了另一个表并删除了记录,因为我将它们添加到新表中 -
Private Sub CmdAppend_Click()
Dim db1 As Database
Dim rstChe As Recordset2
Dim rstCom As Recordset2
Dim qdfChe As DAO.QueryDef
Dim qdfCom As DAO.QueryDef
Dim countlbl As Integer
Dim lblstr As String
Dim stfid As String
Set db1 = CurrentDb
Set qdfChe = db1.QueryDefs("Get_TL_NTL")
qdfChe.Parameters(0) = [Forms]![TeamLeader]![ComClientNotFin]
qdfChe.Parameters(1) = [Forms]![TeamLeader]![ComDateSelect]
Set rstChe = qdfChe.OpenRecordset(dbOpenDynaset)
Set rstCom = db1.OpenRecordset("CompletedChecklistResults", dbOpenDynaset)
rstCom.MoveFirst
rstChe.MoveFirst
If rstChe.BOF Then
MsgBox ("your form did not save please contact administrator")
Else
rstChe.MoveFirst
countlbl = 0
Do Until rstChe.EOF
countlbl = countlbl + 1
rstCom.AddNew
rstCom!DateofChecklist = rstChe.Fields("DateofChecklist").Value
lblstr = Form.Controls("SC" & countlbl).Controls(0).Caption
stfid = Right(lblstr, 7)
rstCom!StaffID = rstChe.Fields("StaffID")
rstCom!ClientID = rstChe.Fields("ClientID")
rstCom!ManagerID = stfid
rstCom!Comments = rstChe.Fields("Comments")
rstCom!Freq = rstChe.Fields("Freq")
rstCom!Questions = rstChe.Fields("Questions").Value
rstCom!DateofChecklist = rstChe.Fields("DateofChecklist")
rstCom!DateCompleted = rstChe.Fields("DateCompleted")
rstCom!DateMngCom = DateValue(CStr(Now()))
rstCom.Update
rstChe.Delete
rstChe.MoveNext
Loop
End If
DoCmd.Close
Set db1 = Nothing
Set rstCom = Nothing
Set rstChe = Nothing
Set qdfChe = Nothing
End Sub