ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 4213|回复: 2

如何在word中调用同一个mdb数据库中的两个表

[复制链接]

TA的精华主题

TA的得分主题

发表于 2005-5-1 16:43 | 显示全部楼层 |阅读模式

DsPath = "e:\编程序相关\Data.mdb" '数据库路径 strPro = "Microsoft.Jet.OLEDB.4.0" '打开数据源的连接 CNN.Open "Provider=" & strPro & ";Data Source=" & DsPath 'SQL查询语句,从名为VariantType的表中读取ID列为值为5的Name列数据 strSQL = "SELECT * FROM 表1 where id = 'now'" '打开该表 RST.Open strSQL, CNN, adOpenKeyset, adLockOptimistic, adCmdText mingjia = RST.Fields("名家明言") mingjianame = RST.Fields("名家名字") mybiaoti = RST.Fields("计划书标题") mydate = Date RST.Close '关闭数据表 Set RST = Nothing '释放对象 Set CNN = Nothing '翻译对象

如果我还想打开一个表格(同一个mdb)我设置如下

strbaodan = "SELECT * FROM 表2 where id = 'now'"

RST.Open strSQL, CNN, adOpenKeyset, adLockOptimistic, adCmdText

但是这里提示错误,请问的二次打开一张表并选取数据,在如何设置上面这段话啊

[此贴子已经被作者于2005-5-1 16:45:45编辑过]

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-5-2 00:31 | 显示全部楼层

请问为什么提示424错误啊

Sub Macro1() Dim CNN As New ADODB.Connection, RST As New ADODB.Recordset Dim CNN1 As New ADODB.Connection, RST2 As New ADODB.Recordset

Dim dspath As String, dspath1 As String, strSQL As String, strSQL1 As String, strPro As String, mingjia As String, mingjianame As String, mybiaoti As String, mytoubaoren As String, myyinyan As String Dim myjieshu As String, mytese As String, mydate As String, myheji As Integer, myheji1, myheji2 Dim mybaoxian1 As String, mybaoxian2 As String, mybaoxian3 As String, mybaoxian4 As String, mybaoxian5 As String, mybaoxian6 As String, mybaoxian7 As String, mybaoxian8 As String, mybaoxian9 As String, mybaoxian0 As String Dim myjiaofei1 As String, myjiaofei2 As String, myjiaofei3 As String, myjiaofei4 As String, myjiaofei5 As String, myjiaofei6 As String, myjiaofei7 As String, myjiaofei8 As String, myjiaofei9 As String, myjiaofei10 As String Dim myqijian1 As String, myqijian2 As String, myqijian3 As String, myqijian4 As String, myqijian5 As String, myqijian6 As String, myqijian7 As String, myqijian8 As String, myqijian9 As String, myqijian10 As String Dim mybaoe1 As String, mybaoe2 As String, mybaoe3 As String, mybaoe4 As String, mybaoe5 As String, mybaoe6 As String, mybaoe7 As String, mybaoe8 As String, mybaoe9 As String, mybaoe10 As String Dim mybaofei1 As String, mybaofei2 As String, mybaofei3 As String, mybaofei4 As String, mybaofei5 As String, mybaofei6 As String, mybaofei7 As String, mybaofei8 As String, mybaofei9 As String, mybaofei10 As String dspath = "e:\编程序相关\Data.mdb" dspath1 = "e:\编程序相关\chinesejoy.mdb" strPro = "Microsoft.Jet.OLEDB.4.0" '打开数据源的连接 CNN.Open "Provider=" & strPro & ";Data Source=" & dspath CNN1.Open "Provider=" & strPro & ";Data Source=" & dspath1 'SQL查询语句,从名为VariantType的表中读取ID列为值为5的Name列数据 strSQL = "SELECT * FROM temp where id = 'now'" strSQL1 = "SELECT * FROM 个人信息 where id = 'now'" '打开该表 RST.Open strSQL, CNN, adOpenKeyset, adLockOptimistic, adCmdText RST1.Open strSQL1, CNN1, adOpenKeyset, adLockOtimistic, adCmdText

就最后一句提示错误。我看了好久都没看出问题出再那里

以下是两个数据库

P7zYDroS.rar (52.35 KB, 下载次数: 23)
[此贴子已经被作者于2005-5-2 0:37:33编辑过]

8rwErOJK.rar

6.39 KB, 下载次数: 24

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-5-2 01:15 | 显示全部楼层

搞定了了。谢谢大家。以下是代码,拿出来共享了。要使用先引用控件

Sub Macro1() Dim CNN As New ADODB.Connection, RST As New ADODB.Recordset Dim CNN1 As New ADODB.Connection, RST1 As New ADODB.Recordset

Dim DsPath As String, dspath1 As String, strSQL As String, strSQL1 As String, strPro As String, mingjia As String, mingjianame As String, mybiaoti As String, mytoubaoren As String, myyinyan As String Dim myjieshu As String, mytese As String, mydate As String, myheji As Integer, myheji1, myheji2 Dim mybaoxian1 As String, mybaoxian2 As String, mybaoxian3 As String, mybaoxian4 As String, mybaoxian5 As String, mybaoxian6 As String, mybaoxian7 As String, mybaoxian8 As String, mybaoxian9 As String, mybaoxian0 As String Dim myjiaofei1 As String, myjiaofei2 As String, myjiaofei3 As String, myjiaofei4 As String, myjiaofei5 As String, myjiaofei6 As String, myjiaofei7 As String, myjiaofei8 As String, myjiaofei9 As String, myjiaofei10 As String Dim myqijian1 As String, myqijian2 As String, myqijian3 As String, myqijian4 As String, myqijian5 As String, myqijian6 As String, myqijian7 As String, myqijian8 As String, myqijian9 As String, myqijian10 As String Dim mybaoe1 As String, mybaoe2 As String, mybaoe3 As String, mybaoe4 As String, mybaoe5 As String, mybaoe6 As String, mybaoe7 As String, mybaoe8 As String, mybaoe9 As String, mybaoe10 As String Dim mybaofei1 As String, mybaofei2 As String, mybaofei3 As String, mybaofei4 As String, mybaofei5 As String, mybaofei6 As String, mybaofei7 As String, mybaofei8 As String, mybaofei9 As String, mybaofei10 As String DsPath = "e:\编程序相关\Data.mdb" dspath1 = "e:\编程序相关\chinesejoy.mdb" strPro = "Microsoft.Jet.OLEDB.4.0" '打开数据源的连接 CNN.Open "Provider=" & strPro & ";Data Source=" & DsPath CNN1.Open "Provider=" & strPro & ";Data Source=" & dspath1 'SQL查询语句,从名为VariantType的表中读取ID列为值为5的Name列数据 strSQL = "SELECT * FROM temp where id = 'now'" strSQL1 = "SELECT * FROM 个人信息 where id = 'now'" '打开该表 RST.Open strSQL, CNN, adOpenKeyset, adLockOptimistic, adCmdText RST1.Open strSQL1, CNN1, adOpenKeyset, adLockOptimistic, adCmdText

mingjia = RST.Fields("名家明言") mingjianame = RST.Fields("名家名字") mybiaoti = RST.Fields("计划书标题") mytoubaoren = RST.Fields("投保人姓名") mytphone = RST1.Fields("电话") myname = RST1.Fields("姓名") myadd = RST1.Fields("公司地址") myinfo = RST.Fields("险种名称") myyinyan = RST.Fields("引言内容") mytese = RST.Fields("保单特色内容") myjieshu = RST.Fields("结束语内容") mybaoxian1 = RST.Fields("险种名称") myqijian1 = RST.Fields("保险期间") myjiaofei1 = RST.Fields("缴费方式") mybaofei1 = RST.Fields("保费") mybaoe1 = RST.Fields("保额") myheji = RST.Fields("合计") mydate = Date RST.Close '关闭数据表 Set RST = Nothing '释放对象 Set CNN = Nothing '翻译对象 RST1.Close '关闭数据表 Set RST1 = Nothing '释放对象 Set CNN1 = Nothing '翻译对象

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-13 15:24 , Processed in 0.036073 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表