将一个Access数据库中表的数据导入(合并到)另一个Access数据库的表中?

zzy198 2001-06-03 05:06:00
有两个数据库文件a.mdb、b.mdb
其中各有一个表C,字段结构都相同
a.mdb的表C中有十条记录
b.mdb的表C中有五条记录

如何将b.mdb中表C的五条记录合并到a.mdb的表C中,既a.mdb的表C中应该有十五条记录。

最好用DAO,实在不行用ADO也行,谢谢大家!
...全文
237 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
OLD_VB_FAN 2001-06-03
关注!!!呵呵,又见到WYO了嘛
回复
wyo 2001-06-03
该例子梢复杂一些,它把两张临时表中的记录拷贝到正式表中.当然加了些判断,相信难不到你


Dim BIAOJI1, BIAOJI2 As String
Dim fapiaoid As Integer
Dim linshifapiao As Integer
Dim gouyanjilu As Integer
Dim response As String
BIAOJI1 = "√"
BIAOJI2 = "×"

Me.MousePointer = ccHourglass '改变鼠标状态为沙漏形
CK.Enabled = False
sql$ = "select * from 临时售货表 WHERE 核定=" & "'" & BIAOJI2 & "'" & " ORDER BY 核定"
myss.Open sql$, strconnect, adOpenStatic, adLockOptimistic, adCmdText

gouyanjilu = myss.RecordCount


'核定未经核定的记录
If gouyanjilu > 0 Then
response = MsgBox("您有" & gouyanjilu & "条购盐记录未经核定,需要自动核定吗?", vbQuestion + vbYesNo + vbDefaultButton2, "核定购盐记录") '提示

If response = vbYes Then

Do Until myss.eof
linshifapiao = myss!发票ID
sql0$ = "select * from 临时销售表 WHERE 发票ID =" & linshifapiao
myss0.Open sql0$, strconnect, adOpenStatic, adLockOptimistic, adCmdText

'如果只输入客户,而没输入购盐信息,该发票不核定
If myss0.RecordCount > 0 Then
myss!核定 = BIAOJI1
myss.Update
End If
myss0.Close
myss.MoveNext
Loop

End If

End If
myss.Requery '刷新数据库
myss.Close


'拷贝记录到销售表和售货表,所有的查询和报表将都在这两个表的基础上进行
sql1$ = "select * from 临时售货表 WHERE 核定=" & "'" & BIAOJI1 & "'" & " ORDER BY 发票ID"
myss1.Open sql1$, strconnect, adOpenStatic, adLockOptimistic, adCmdText

sql2$ = "select * from 售货表 ORDER BY 发票ID"
myss2.Open sql2$, strconnect, aadOpenKeyset, adLockOptimistic, adCmdText

sql4$ = "select * from 销售表 ORDER BY 发票ID"
myss4.Open sql4$, strconnect, aadOpenKeyset, adLockOptimistic, adCmdText

If myss1.RecordCount = 0 Then
myss1.Close
myss2.Close
myss4.Close
Unload Me
Exit Sub
End If


Do Until myss1.eof
myss2.AddNew

myss2!日期 = myss1!日期
myss2!客户ID = myss1!客户ID
myss2!客户 = myss1!客户
myss2!职员ID = myss1!职员ID
myss2!制单 = myss1!制单
myss2!发票ID = myss1!发票ID
myss2!票号 = myss1!票号
myss2!含 = myss1!含
myss2!税率 = myss1!税率
myss2!扣 = myss1!扣
myss2!扣率 = myss1!扣率
myss2!科目ID = myss1!科目ID
myss2!付款方式 = myss1!付款方式
myss2!库存类型 = myss1!库存类型
myss2!总计 = myss1!总计

fapiaoid = myss1!发票ID
sql3$ = "select * from 临时销售表 WHERE 发票ID=" & fapiaoid & " ORDER BY 发票ID"
myss3.Open sql3$, strconnect, adOpenStatic, adLockOptimistic, adCmdText

Do Until myss3.eof
myss4.AddNew

myss4!发票ID = myss3!发票ID
myss4!商品ID = myss3!商品ID
myss4!库位ID = myss3!库位ID
myss4!商品名称 = myss3!商品名称
myss4!商品品种 = myss3!商品品种
myss4!单位 = myss3!单位
myss4!数量 = myss3!数量
myss4!单价 = myss3!单价
myss4!金额 = myss3!金额
myss4!税额 = myss3!税额
myss4!回扣 = myss3!回扣
myss4!回扣税额 = myss3!回扣税额
myss4!品种ID = myss3!品种ID
myss3.Delete
myss3.MoveNext
Loop
myss3.Close

myss1.Delete
myss1.MoveNext
Loop

'myss1.Update
myss2.Update
myss4.Update
myss2.Requery
myss4.Requery

myss1.Close
myss2.Close
myss4.Close

Unload Me

回复
shineyz 2001-06-03
insert into [;database=a.mdb].c select * from c
回复
相关推荐
发帖

1188

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
帖子事件
创建了帖子
2001-06-03 05:06
社区公告
暂无公告