Sub inputdatas() On Error GoTo input_err Dim conn As New ADODB.Connection Dim rst As New ADODB.Recordset Dim sql As String, tem ' 第一个问题:tem是access数据库已经存在的表,我是想把“tem”定义为access对象的一张表,如何定义? Set conn = New ADODB.Connection conn.Open "Provider=MSDASQL;DRIVER=SQL Server; SERVER=10.81.70.212;DATABASE=MS_work; UID=ms; PWD=123" sql = "select date,ID,out from dbo.m200712_CENTER where ID='12' and date='2007-12-10'" Set rst = New ADODB.Recordset rst.CursorLocation = adUseClient rst.Open sql, conn rst.MoveFirst '第二个问题:怎样把连接sql查到的数据放进本地的“tem”表中。下面代码开始出错. Do Until rst.EOF tem.AddNew tem!date = rst!Date tem!ID = rst!Id tem!out = rst!out tem.Update rst.MoveNext Loop rst.Close input_exit: Exit Sub input_err: MsgBox Err.Description Resume input_exit End Sub 重点:在Access中,编写VBA代码,连上后台SQL服务器,并用SQL查找想要的数据,之后再更新到本地Access的一张表中.如何实现将已查的数据更新到本地表?
[此贴子已经被作者于2007-12-10 18:34:10编辑过] |