作者: hjb016 时间: 2010-9-13 13:03
dim ssql as string
dim strWhere as string
dim rs as dao.recordset
on error resume next '这个必须加,这样如果记录重复,自动循环下一条记录
set rs=currentdb.openrecordset("select * from " & stbname)
ssql="INSERT INTO 目标表"
ssql=ssql & " select * from 源表 "
do While Not Rs.EOF
Sub MyInsert(tbname as string,Stbname as string,SPath as string,WH as string)
'功能:将外部表数据追加到目标表中
'参数: tbname--目标表名称字符串
' Stbname--源表名称字符串
' Spath--原表所在数据库完成文件名(含路径)
' WH--两表比较字数串
'示例: MyInsert "学生表","学生资料","F:\成绩管理系统.mdb","b.姓名=a.姓名 and b.性别=a.性别"
dim ssql as string
ssql="INSERT INTO " & tbname
ssql=ssql & " select * from " & stbname & " as a"
ssql=ssql & " in " & Spath
ssql=ssql & " where not EXISTS (select * from " & tbname & " as b where " & WH & " )"
docmd.runsql ssql
end sub