煮江品茶老师:
我又修改了一下,但还是无法通过,在黑体字处提示” 运行时错误 ' 3705 ' 对象打开时,不允许操作“,望老师能抽空指点,确有急用,再次谢谢了......
Private Sub Command13_Click()
Dim wApp As New Word.Application
Dim doc As Word.Document
Dim rs As New ADODB.Recordset
Dim rsa As New ADODB.Recordset
Dim ssql As String
Dim ssql1 As String
Dim wtlb As String
Dim wtdx As String
Dim i As Long
Dim j As Long
Set doc = wApp.Documents.Add
ssql = "select * from 类型统计查询 "
rs.Open ssql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
For i = 1 To rs.RecordCount
doc.Application.Selection.TypeText Text:=rs.Fields(0).Value & ":"
doc.Application.Selection.TypeParagraph
doc.Application.Selection.TypeText Text:=rs.Fields(1).Value & "," & rs.Fields(2).Value & "问题" & "" & rs.Fields(3).Value & "" & "条,总涉及金额:" & "" & rs.Fields(4).Value & "" & "万元。"
doc.Application.Selection.TypeParagraph
doc.Application.Selection.TypeText Text:="具体事例:"
doc.Application.Selection.TypeParagraph
wtlb = rs.Fields(0).Value
wtdx = rs.Fields(2).Value
ssql1 = "select * from A "
ssql1 = ssql1 & "where (类别 = " & " '" & wtlb & "' " & " and 定性 = " & "'" & wtdx & "'" & ")"
rsa.Open ssql1, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
For j = 1 To rsa.RecordCount
doc.Application.Selection.TypeText Text:=rsa.Fields(9).Value & ";"
doc.Application.Selection.TypeParagraph
doc.Application.Selection.TypeText Text:=rsa.Fields(11).Value & ";"
doc.Application.Selection.TypeParagraph
rsa.MoveNext
Next
doc.Application.Selection.TypeParagraph
rs.MoveNext
Next
'doc.SaveAs folderpath & "\" & tbname & ".doc"
doc.SaveAs "C:\Users\admin\汇总报告.doc"
wApp.Quit True
rs.Close: Set rs = Nothing
Set wApp = Nothing
Set doc = Nothing
End Sub