将一个表中的记录插入到另一个表中 [英] Inserting a record from one table into another

查看:71
本文介绍了将一个表中的记录插入到另一个表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Access VBA 代码作为用户表单上的点击按钮.

I have in Access VBA code as an on-click button on a userform.

我有两个重复的表(PrintTable 和 ManPowerCalculator),我试图将 ManPowerCalculator 表中的每个项目插入到 PrintTable 中,其中用户表单上的 EmplID 输入框 = ManPowerCalculator 表中的输入框.

I have two duplicate tables (PrintTable & ManPowerCalculator) and I am trying to insert every item from ManPowerCalculator table into the PrintTable where the EmplID input box on the userform = that within the ManPowerCalculator Table.

CurrentDb.Execute "INSERT INTO PrintTable VALUES (*) SELECT (*)FROM ManPowerCalculator WHERE EmplID # = " & Me.EmplID "

我没有定义任何变量,也许这样可以提高效率.

I am not defining any variables, maybe it would make it more efficient.

推荐答案

这应该可以:

CurrentDb.Execute "INSERT INTO PrintTable SELECT * FROM ManPowerCalculator WHERE EmplID = " &Me.EmplID

请注意,这仅在 PrintTable 和 ManPowerCalculator 表具有完全相同的字段时才有效.如果没有,您将必须在查询的 INSERT 和 SELECT 部分中指定字段名称.

Note that this will only work if the PrintTable and ManPowerCalculator tables have the exact same fields. If they don't, you will have to specify the field names both in the INSERT and SELECT parts of the query.

这是按照以下格式完成的:

This is done in the following format:

CurrentDb.Execute "INSERT INTO PrintTable (x, y, z) SELECT x, y, z FROM ManPowerCalculator WHERE EmplID = " &Me.EmplID

x、y 和 z 是可能的字段名称.

With x, y and z being possible field names.

这篇关于将一个表中的记录插入到另一个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆