代码是在这里COPY的,也不知道是怎么回事。代码如下
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Sub GetInformation()
conn.Open "provider=microsoft.jet.oledb.4.0;data source=e:\test.mdb"
rs.Open "select * from t1", conn, adOpenKeyset, adLockOptimistic, adCmdText
For i = 0 To rs.Fields.Count - 1
ActiveDocument.Tables(1).Cell(1, i + 1).Range.InsertAfter rs.Fields(i).Name
Next
End Sub
下面的这段代码也是copy后自己改的,运行结果如下图,也搞不懂,从头学就是难啊
Sub OpenASC()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql
Dim i
Dim outstr
Dim tt
'xiaoxi = InputBox("您要在Word文章中插入哪个字段的消息?" & Chr(13) & "字段有ID、作者、具体内容三个。")
sql = "select * from t1"
conn.Provider = "microsoft.jet.oledb.4.0"
conn.Open "e:\test.mdb"
'路径与文件为假定的"
'用下面这句也行!
'conn.Open "provider=microsoft.jet.oledb.4.0;data source=D:\A\b\jjngyy.mdb"
rs.Open sql, conn, adOpenKeyset, adLockOptimistic, adCmdText
''以下取出十条记录
For i = 1 To 3
If i <= rs.RecordCount Then
outstr = outstr & i & rs(tt)
rs.MoveNext
End If
Next
ActiveDocument.Range(0, 0) = (outstr)
conn.Close
Set conn = Nothing
End Sub
|