我有一个临时表,可以保存数据,最终创建一个完整的记录。我正在尝试设置它,所以当你单击一个按钮时它会从临时表中获取数据,将它放入主表中,然后删除临时表中的旧记录。
我试图使用此代码,但似乎VBA编辑器中没有足够的空间(因为我的所有列名称似乎太长而且它们太多了)
strSQL = "Insert Into ProjectsT (CustomerName, ProjectName, ProjectDesc, DateOfPurchase, ProjectDueDate, EngineerDueDate, CutplanDueDate, HardwareDueDate, ProjectComplete, EngineerComplete, CutplanComplete, HardwareComplete, WorkOrder, MaterialSpecs, CutplanPattern, Milestones, HardwareSpecs, SupplierName, ProjFilePath, DrawFilePath, DetailFilePath, CostFilePath, ProjectStartDate, EngineerStartDate, CutplanStartDate, HardwareStartDate, PackageReleasedToShop, EstAssemblyHours, CuttingDueDAte, TrakwareNumber) Select CustomerName, ProjectName, ProjectDesc, DateOfPurchase, ProjectDueDate, EngineerDueDate, CutplanDueDate, HardwareDueDate, ProjectComplete, EngineerComplete, CutplanComplete, HardwareComplete, WorkOrder, MaterialSpecs, CutplanPattern, Milestones, HardwareSpecs, SupplierName, ProjFilePath, DrawFilePath, DetailFilePath, CostFilePath, ProjectStartDate, EngineerStartDate, CutplanStartDate, HardwareStartDate, PackageReleasedToShop, EstAssemblyHours, CuttingDueDAte, TrakwareNumber From ProjectsTempT Where ID=" & Me.txtID & ";"
我如何设置它以便它可以将数据从临时表复制到主表中,如果所有列的名称相同,并且有多个/多个名称?
答案 0 :(得分:2)
“我如何设置它以便它可以将数据从临时表复制到主表,如果所有列的名称相同,并且有多个/多个名称?” < / p>
当您的INSERT
为目标表中的所有字段提供值时,您可以省略表名后面的字段列表。
INSERT INTO ProjectsT
SELECT *
FROM ProjectsTempT;
我没有使用WHERE
条款来保持简单。
但我不明白为什么你的第一次尝试(带有字段名称列表)失败了。 (是否有错误消息?)使用Access'查询设计器构建SELECT
查询,并将ProjectsTempT
字段添加到网格的下半部分。然后将查询类型更改为“追加”。在网格中,为源表中的每个字段选择匹配的目标表字段。假设该方法为您提供了有效的查询,请切换到SQL View以检查语句文本。修改VBA代码以生成相同的语句。或者使查询设计器版本成为参数查询,保存它,并从VBA调用该命名查询。
答案 1 :(得分:1)
你试过这个吗?
strSQL = "Insert Into ProjectsT (CustomerName, ProjectName, ProjectDesc, DateOfPurchase, ProjectDueDate, EngineerDueDate, CutplanDueDate, HardwareDueDate, ProjectComplete, EngineerComplete, CutplanComplete, HardwareComplete, WorkOrder, MaterialSpecs, CutplanPattern, Milestones, " & _
strSQL = strSQL & "HardwareSpecs, SupplierName, ProjFilePath, DrawFilePath, DetailFilePath, CostFilePath, ProjectStartDate, EngineerStartDate, CutplanStartDate, HardwareStartDate, PackageReleasedToShop, EstAssemblyHours, CuttingDueDAte, TrakwareNumber) " & _
strSQL = strSQL & "Select CustomerName, ProjectName, ProjectDesc, DateOfPurchase, ProjectDueDate, EngineerDueDate, CutplanDueDate, HardwareDueDate, ProjectComplete, EngineerComplete, CutplanComplete, HardwareComplete, WorkOrder, MaterialSpecs, CutplanPattern, Milestones, " & _
strSQL = strSQL & "HardwareSpecs, SupplierName, ProjFilePath, DrawFilePath, DetailFilePath, CostFilePath, ProjectStartDate, EngineerStartDate, CutplanStartDate, HardwareStartDate, PackageReleasedToShop, EstAssemblyHours, CuttingDueDAte, TrakwareNumber " & _
strSQL = strSQL & "From ProjectsTempT Where ID=" & Me.txtID & ";"
有时它只是无法立即处理整个块,所以你需要分解它。如果这不起作用,您始终可以使用DoCmd.OpenQuery创建一个追加查询并通过代码运行它