2

我有一个临时表,用于保存数据片段,最终创建完整记录。我正在尝试设置它,因此当您单击一个按钮时,它会从临时表中获取数据,将其放入主表中,然后删除临时表中的旧记录。

我试图使用这段代码,但似乎 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 & ";"

如果所有列的名称都相同,并且有这么多/长的名称,我将如何设置它以便它可以将临时表中的数据复制到主表中?

4

2 回答 2

2

“如果所有列的名称都相同,并且有这么多/长的名称,我将如何设置它以便它可以将临时表中的数据复制到主表中?”

当您INSERT为目标表中的所有字段提供值时,您可以省略表名后面的字段列表。

INSERT INTO ProjectsT
SELECT *
FROM ProjectsTempT;

WHERE为了简单起见, 我省略了该子句。

但我不明白为什么您的第一次尝试(使用字段名称列表)失败了。(是否有错误消息?)SELECT使用 Access 的查询设计器构建查询并将ProjectsTempT字段添加到网格的下部。然后将查询类型更改为“追加”。在网格中,为源表中的每个字段选择匹配的目标表字段。假设该方法为您提供了一个有效的查询,请切换到 SQL 视图来检查语句文本。修改 VBA 代码以生成相同的语句。或者使查询设计器版本成为参数查询,保存它,然后从 VBA 调用该命名查询。

于 2013-11-12T15:15:19.077 回答
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 通过代码运行它

于 2013-11-12T15:16:23.123 回答