如何在word中控制记录换行
另外这段程序运行后,为什么记录没有能够送入到word中,请朋友们帮我看看
Public conn As ADODB.Connection
Dim str As New ADODB.Recordset
Private Sub Command1_Click()
Dim i As Integer, j As Integer
Dim ifieldcount As Integer, irecordcount As Integer
Dim wdapp As Word.Application
Dim wddoc As Word.Document
Dim atable As Word.Table
With str
.MoveLast
.MoveFirst
ifieldcount = .Fields.Count
irecordcount = .RecordCount
End With
On Error Resume Next
'创建word应用程序,打开word2003
Set wdapp = CreateObject("Word.Application")
'在word中添加一个新文档
Set wddoc = wdapp.Documents.Add
With wdapp
.Visible = True
.Activate
'在word中增加一个表格
Set stable = .ActiveDocument.Tables.Add(.Selection.Range, irecordcount + 1, ifieldcount)
For i = 0 To ifieldcount - 1
atable.Cell(1, i + 1).Range.InsertAfter DataGrid1.Columns(i)
Next i
'指定表格内容
str.MoveFirst
For i = 0 To irecordcount - 1
For j = 0 To ifieldcount - 1
atable.Cell(i + 2, j + 1).Range.InsertAfter str.Fields(j)
Next j
str.MoveNext
Next i
End With
'清除word 对象
Set wdapp = Nothing
Set wddoc = Nothing
End Sub
Private Sub Form_Load()
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;" _
+ "User ID=sa;password=sa;Initial Catalog=ComSys;Data Source=127.0.0.1"
conn.Open
strsql = "select 编号,货物编号,货物名称,计量单位,经办人,出库时间,出库单价,出库数量,金额,客户,存放仓库,备注 from out_warehouse"
Set str = New ADODB.Recordset
If str.State = adStateOpen Then str.Close
str.CursorLocation = adUseClient
str.Open strsql, conn, adOpenStatic, adLockBatchOptimistic
Set DataGrid1.DataSource = str
End Sub
[此贴子已经被作者于2006-6-17 18:56:54编辑过]