MS Access VBA SQL-将记录从一个表插入到另一个表 [英] MS Access VBA SQL - Inserting a record from one table into another table

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

问题描述

Hello Stackoverflow社区

Hello Stackoverflow community,

下面是我在Access VBA中作为用户窗体上的单击按钮获得的代码。如您所知,我对VBA& SQL,但试图修改我的公司数据库之一。我有两个重复的表(PrintTable& ManPowerCalculator),我试图将ManPowerCalculator表中的每个项目插入到PrintTable中,其中用户窗体上的EmplID输入框= ManPowerCalculator表中的输入框。

Below is the code I have in Access VBA as an on-click button on a userform. As you can tell I have very limited knowledge in VBA & SQL but trying to revise one of my companies databases. 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 "

我也没有定义任何变量,也许会使它更有效。谢谢

Also I am not defining any variables, maybe it would make it more efficient. Thank you for your time in reading through this.

推荐答案

这应该可以完成工作:

CurrentDb。执行插入到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。执行插入打印表(x, y,z)从ManPowerCalculator中选择x,y,z EmplID =& Me.EmplID

其中x,y和z为可能的字段名称。

With x, y and z being possible field names.

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

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