Office中国论坛/Access中国论坛

标题: 关于同时打开两个数据源的问题 [打印本页]

作者: dksteycx    时间: 2009-5-1 18:21
标题: 关于同时打开两个数据源的问题
要同时打开两张表,将表1的某些字段粘贴到表2中来,用什么语句啊

下面这些语句可以吗   
Dim con1,con2 As New ADODB.Connection
    Dim rcord1,rcord2 As New ADODB.Recordset
    Set con1 = CurrentProject.Connection
    rcord1.Open " SELECT *  from 表1" con, adOpenKeyset, adLockPessimistic
    rcord1.Open " SELECT *  from 表2" con, adOpenKeyset, adLockPessimistic
作者: todaynew    时间: 2009-5-1 18:37
dim rs1 as New ADODB.Recordset
dim rs2 as New ADODB.Recordset
dim sql1 as string
dim sql2 as string
sql1=" SELECT *  from 表1"
sql2=" SELECT *  from 表2"
rs1.Open sql1, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
rs2.Open sql2, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
.......
作者: dksteycx    时间: 2009-5-1 18:37
太好了,我试试看
作者: todaynew    时间: 2009-5-1 18:41
本帖最后由 todaynew 于 2009-5-1 18:47 编辑
太好了,我试试看
dksteycx 发表于 2009-5-1 18:37

可以参考下面的例子:

本帖最后由 todaynew 于 2009-4-23 15:48 编辑

Private Sub 加权法()
Dim rs1 As New ADODB.Recordset
Dim sql1 As String
Dim rs2 As New ADODB.Recordset
Dim sql2 As String
Dim 累计数量 As Single
Dim 累计金额 As Single
Dim 单价 As Single

Dim i as Long
sql1 = "select * from 发料查询 where format(日期,'yymm')='" & Me.月度.Value & "'and 物资ID=" & Me.物资ID.Value
rs1.Open sql1, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
sql2 = "select * from 库存及收料查询 where format(日期,'yymm')='" & Me.月度.Value & "'and 物资ID=" & Me.物资ID.Value
rs2.Open sql2, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
累计数量 = 0
累计金额 = 0
For i = 1 To rs2.RecordCount
    累计数量 = 累计数量 + rs2("数量")
    累计金额 = 累计金额 + rs2("金额")
    rs2.MoveNext
Next
单价 = Round(累计金额 / 累计数量, 2)
For i = 1 To rs1.RecordCount
    rs1("单价") = 单价
    rs1("金额") = rs1("数量") * rs1("单价")
    rs1.Update
    rs1.MoveNext
Next
Me.收发子窗体.Form.Requery
rs1.Close
rs2.Close
End Sub



作者: tz-chf    时间: 2009-5-1 21:44
表2不需要返回所有记录




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3