正在学习VB6.0,用datareport设计报表带打印,哪位大哥给个实例瞧瞧啊?
1个回答
展开全部
'首先运行VB,选择“工程_引用”命令,引用 Microsoft ActiveX Data Objects 2.5 Library
'添加一个报表控件DataReport,按要求布置好RptTextBox,日期DTPicker1\ DTPicker2,打印按钮,双击command1按钮添加代码:
Private Sub Command1_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim Sql As String
'连接数据库(Access)
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path & "\slw2000.mdb" + ";Persist Security Info=False"
'打开记录集( 根据日期查询 )
Set rs = New ADODB.Recordset
Sql = "select 产品代号,原料名,重量,日期,内部码,外部码 from 配料记录 " & _
"where 日期 between #" & Format(DTPicker1, "yyyy-mm-dd") & "# and #" & Format(DTPicker2, "yyyy-mm-dd") & "#"
rs.Open Sql, cn, adOpenKeyset, adLockOptimistic
'设置text控件属性
DataReport1.Sections("Section1 ").Controls("RptTextBox1 ").DataField = 产品代号
DataReport1.Sections("Section1 ").Controls("RptTextBox2 ").DataField = 原料名
DataReport1.Sections("Section1 ").Controls("RptTextBox3 ").DataField = 重量
DataReport1.Sections("Section1 ").Controls("RptTextBox4 ").DataField = 日期
DataReport1.Sections("Section1 ").Controls("RptTextBox5 ").DataField = 内部码
DataReport1.Sections("Section1 ").Controls("RptTextBox6 ").DataField = 外部码
Set DataReport1.DataSource = rs
End Sub
Private Sub Form_Load()
DTPicker1.Value = Date
DTPicker2.Value = Date
End Sub
'添加一个报表控件DataReport,按要求布置好RptTextBox,日期DTPicker1\ DTPicker2,打印按钮,双击command1按钮添加代码:
Private Sub Command1_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim Sql As String
'连接数据库(Access)
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path & "\slw2000.mdb" + ";Persist Security Info=False"
'打开记录集( 根据日期查询 )
Set rs = New ADODB.Recordset
Sql = "select 产品代号,原料名,重量,日期,内部码,外部码 from 配料记录 " & _
"where 日期 between #" & Format(DTPicker1, "yyyy-mm-dd") & "# and #" & Format(DTPicker2, "yyyy-mm-dd") & "#"
rs.Open Sql, cn, adOpenKeyset, adLockOptimistic
'设置text控件属性
DataReport1.Sections("Section1 ").Controls("RptTextBox1 ").DataField = 产品代号
DataReport1.Sections("Section1 ").Controls("RptTextBox2 ").DataField = 原料名
DataReport1.Sections("Section1 ").Controls("RptTextBox3 ").DataField = 重量
DataReport1.Sections("Section1 ").Controls("RptTextBox4 ").DataField = 日期
DataReport1.Sections("Section1 ").Controls("RptTextBox5 ").DataField = 内部码
DataReport1.Sections("Section1 ").Controls("RptTextBox6 ").DataField = 外部码
Set DataReport1.DataSource = rs
End Sub
Private Sub Form_Load()
DTPicker1.Value = Date
DTPicker2.Value = Date
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询