这只是我的一个偿试,不一定满足楼主要求: '* +++++++++++++++++++++++++++++
'* Created By I Love You_Word!@ExcelHome 2005-4-21 6:09:16
'仅测试于System: Windows NT Word: 10.0 Language: 2052
'^The Code CopyIn [ThisDocument-ThisDocument]^'
'* -----------------------------Option Explicit
'运行此代码前,请在VBE/工具/引用中勾选:Microsoft ActiveX Data Object 2.6 Library
'由于本人首次操作数据库对象与SQL语句,注释处不一正确,有待于进一步勘查
Sub Example()
Dim CNN As New ADODB.Connection, RST As New ADODB.Recordset
Dim Stpath As String, strSQL As String, i As Integer, MyString As String
Stpath = "C:\WINNT\system32\ias\ias.mdb" '数据库路径
'打开指定数据库
CNN.Open "provider=Microsoft.jet.OLEDB.4.0;data source=" & Stpath
'SQL查询语句,从名为Properties的表中读取StrVal列为0的Name列数据
strSQL = "select Name from Properties WHERE StrVal=""0"""
'读取数据库
RST.Open strSQL, CNN, adOpenKeyset, adLockOptimistic, adCmdText
For i = 1 To RST.RecordCount '从1到符合条件的所有记录数中循环
MyString = MyString & RST.Fields("Name") & vbCrLf '内存变量中累加
RST.MoveNext '向下移动记录指针
Next i
RST.Close '关闭数据表
Set RST = Nothing '释放对象
Set CNN = Nothing '翻译对象
Selection.InsertAfter MyString '将文本插入
End Sub
'---------------------- |