/question/4165080.html
報表打印代碼:
Option Explicit
Private n As Integer
Private m As Integer
Private zh_dm(10) As Double
Private dy_dm(3000, 10) As Variant
Private zsl As Integer
Private y As Integer
Private x As Integer
Private i As Integer
Private k As Integer
Private p As Integer
Private pa As Integer
Private j As Integer
Private txt As String
Private fnt As Integer
Private dd As Variant
Public Function prnt(x As Variant, y As Variant, fnt As Variant, txt0 As Variant)
Printer.CurrentX = x
Printer.CurrentY = y
Printer.FontSize = fnt
Printer.Print txt0
End Function
Private Sub cmdPrint_Click()
Adodc1.Recordset.MoveFirst
For i = 0 To zsl - 1
For j = 0 To 7
dy_dm(i, j) = Adodc1.Recordset(j)
Next j
Adodc1.Recordset.MoveNext
Next i
'確定頁數
k = Int(zsl / 80)'80為每頁行數
If k - zsl / 80 < 0 Then
k = k + 1
End If
fnt = 8
For p = 0 To k - 1
pa = p + 1
y = 300
x = 4500
txt = "機物料庫存"
dd = prnt(x, y, fnt, txt)
x = 8500
txt = "第" & p + 1 & "頁"
dd = prnt(x, y, fnt, txt)
y = 500
x = 600
txt = "備件代碼"
dd = prnt(x, y, fnt, txt)
x = 1500
txt = "備件名稱"
dd = prnt(x, y, fnt, txt)
x = 3500
txt = "備件規格"
dd = prnt(x, y, fnt, txt)
x = 5500
txt = "進口計算機號"
dd = prnt(x, y, fnt, txt)
x = 7500
txt = "最低儲備量"
dd = prnt(x, y, fnt, txt)
x = 9000
txt = "庫存量"
dd = prnt(x, y, fnt, txt)
For i = 0 + p * 80 To 79 + p * 80
y = 700 + 180 * (i - p * 80)
x = 600
txt = dy_dm(i, 1)
dd = prnt(x, y, fnt, txt)
x = 1500
txt = dy_dm(i, 2)
dd = prnt(x, y, fnt, txt)
x = 3500
txt = dy_dm(i, 3)
dd = prnt(x, y, fnt, txt)
x = 5500
txt = dy_dm(i, 4)
dd = prnt(x, y, fnt, txt)
x = 7500
txt = dy_dm(i, 5)
dd = prnt(x, y, fnt, txt)
x = 9000
txt = dy_dm(i, 6)
dd = prnt(x, y, fnt, txt)
If Int(i / 10) - i / 10 = 0 Then
Printer.Line (500, 695 + (i - p * 80) * 180)-(10000, 695 + (i - p * 80) * 180)
End If
Next i
If zsl - p * 80 > 80 Then
Printer.Line (500, 695 + 180 * 80)-(10000, 695 + 180 * 80)
Printer.NewPage
End If
Next p
Printer.EndDoc ' 打印完成。
Cls
End Sub
Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=jwl_dbf"
Adodc1.RecordSource = "select cs.js_dm,cs.備件代碼,cs.備件名稱,cs.備件規格,cs.進口計算機號,cs.最低庫存量,sl.結存數量,sl.結存金額,sl.結存單價,sl.類別代碼 from JWCK_BM as cs,jwl_jiec as sl" & _
" where cs.備件代碼 = sl.備件代碼" & " and cs.備件代碼>" & "''" & " order by sl.類別代碼,sl.備件代碼"
Adodc1.Refresh
DataGrid1.Refresh
zsl = Adodc1.Recordset.RecordCount
Adodc3.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=jwl_dbf"
Adodc3.RecordSource = "select sum(結存金額) as hj from jwl_jiec"
Adodc3.Refresh
End Sub
以上供參考。其它請參考西安交通大學出版社出版的“VISUAL BASIC 6.0 高級編程技巧-ADO數據訪問篇“