Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 根据表中的记录数将数据追加到access表中_Sql_Ms Access_Vba_Ms Access 2010 - Fatal编程技术网

Sql 根据表中的记录数将数据追加到access表中

Sql 根据表中的记录数将数据追加到access表中,sql,ms-access,vba,ms-access-2010,Sql,Ms Access,Vba,Ms Access 2010,我是新访问VBA, 我的方案是从另一个表中选择表名 (In same access db (table name as parameter)). 根据从参数中选择的表名,我需要从同一个tableParmater中选择le列。然后我要检查distinct le from参数。 基于参数表中不同的LE4,我想将记录附加到另一个表ULAE中。 append语句将作为insert into,where条件作为LE from参数表 代码给出了错误2342。CMDSQL需要sql语句 有人能建议如何实施

我是新访问VBA, 我的方案是从另一个表中选择表名

(In same access db (table name as parameter)). 
根据从参数中选择的表名,我需要从同一个tableParmater中选择le列。然后我要检查distinct le from参数。 基于参数表中不同的LE4,我想将记录附加到另一个表ULAE中。 append语句将作为insert into,where条件作为LE from参数表

代码给出了错误2342。CMDSQL需要sql语句

有人能建议如何实施它吗


感谢您的帮助

这是通过创建函数实现的

Function LinkTables()

Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim stringsql As String
Set rs1 = CurrentDb.OpenRecordset("Table Valued Parameter")

While Not rs1.EOF = True

'MsgBox rs1![Table_name]
'MsgBox rs1![le]

tblname = rs1!Table_name

legal_entity = rs1.Fields(1)

NEW_TBLNAME = rs1![destination_table]

DoCmd.SetWarnings False

DoCmd.RunSQL ("INSERT INTO " & NEW_TBLNAME & " SELECT * FROM " & tblname & " where le = '" & legal_entity & "'")

DoCmd.SetWarnings True

rs1.MoveNext

Wend

MsgBox "Tables Refreshed"


End Function

你的问题不清楚。你能改进你的问题吗?您是否尝试根据另一个表中的参数将记录导出到新表中?
Function LinkTables()

Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim stringsql As String
Set rs1 = CurrentDb.OpenRecordset("Table Valued Parameter")

While Not rs1.EOF = True

'MsgBox rs1![Table_name]
'MsgBox rs1![le]

tblname = rs1!Table_name

legal_entity = rs1.Fields(1)

NEW_TBLNAME = rs1![destination_table]

DoCmd.SetWarnings False

DoCmd.RunSQL ("INSERT INTO " & NEW_TBLNAME & " SELECT * FROM " & tblname & " where le = '" & legal_entity & "'")

DoCmd.SetWarnings True

rs1.MoveNext

Wend

MsgBox "Tables Refreshed"


End Function