程序资源下载:点击下载
一、问题描述:
一张A4纸模板,上面一段文字,但中间一些地方空白,需要我们填上一些信息,本文中我们将数据库表ych中的字段信息(dw,xm,cs,gz,sfzhm)打钱到模板上。
二、程序实现原理:
(1)定义一个数组和编写一个打印函数
(2)按记录条数进行循环,再对每一条记录按字段数目进行循环,将后台Access记读取到数组中
三:实验数据:
1、表记录内容如下:
2、字段定义如下:
3、打印模板:
四、程序实现
1、程序功能:
(1)按每条记录分散的打印到模板上
(2)如果需要打印的记录数量太多,可以在文本框中设置打印数量
(3)为了避免误操作,只有点击了“待打查询”按钮后,“打印”按钮才能打印
(4)一条记录打印完毕之后,标志位flag将由初始化的“0”变后“1”再次点击“待打查询”标志位为“1”的记录将不再显示
2、运行截图如下:
3、程序实现代码:
Private Sub Command1_Click() Dim d As Integer Dim s As String Adodc3.CommandType = adCmdText s = "select * from ych where flag='0' " Adodc3.RecordSource = s Adodc3.Refresh d = Adodc3.Recordset.RecordCount Label7.Caption = d Dim db,rs Dim ssql As String Set db = CreateObject("ADODB.Connection") db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb" 'ssql = "select * from sy2013 where xzmc='" & Combo1.Text & "' " ssql = "select * from sy2013 where flag='0' " Set rs = CreateObject("adodb.recordset") rs.Open ssql,db,1,1 Dim a fnt = 15 Adodc1.Recordset.MoveFirst For i = 0 To zsl - 1 For j = 0 To 4 dy_dm(i,j) = Adodc1.Recordset(j) Next j Adodc1.Recordset.MoveNext y = 3800 x = 1500 txt = dy_dm(i,0) dd = prnt(x,y,fnt,txt) y = 3800 x = 6900 txt = dy_dm(i,1) dd = prnt(x,txt) y = 4450 x = 2500 txt = dy_dm(i,2) dd = prnt(x,txt) y = 4450 x = 5350 txt = dy_dm(i,3) dd = prnt(x,txt) y = 4450 x = 4900 txt = dy_dm(i,4) a = txt db.Execute ("update ych set flag= '1'where sfzhm='" & a & "'") Printer.EndDoc ' 打印完成。 Cls Printer.NewPage d = d - 1 Label7.Caption = d Next i rs.Close Set rs = Nothing Set db = Nothing End Sub Private Sub Command2_Click() Dim strquery As String strquery = "select * from ych where flag<> '1' " Adodc1.CommandType = adCmdText Adodc1.RecordSource = strquery Adodc1.Refresh If (Text1.Text = "") Then zsl = Adodc1.Recordset.RecordCount Else zsl = Val(Text1.Text) End If Command1.Enabled = True Text1.Enabled = False End Sub