VB6中动态设置报表结果
想不想get新技能酷炫一下,今天图老师小编就跟大家分享个简单的VB6中动态设置报表结果教程,一起来看看吧!超容易上手~
PrivateSubCommand11_Click()
OnErrorResumeNext
DimsqlAsString
sql="select*fromsaledate"
IfDataEnvironment1.rsCommand1.StateadStateClosedThen
DataEnvironment1.rsCommand1.Close
EndIf
IfRight$(Trim$(App.Path),1)=""Then
DataEnvironment1.Connection1.OpenApp.Path&"jxck.mdb"
Else
DataEnvironment1.Connection1.OpenApp.Path&"jxck.mdb"
EndIf
DataEnvironment1.rsCommand1.Opensql
SetDataReport1.DataSource=DataEnvironment1
DataReport1.DataMember="command4"
'DataReport1.Title="出库明细总表"
DataReport1.Show
EndSub
这样的话报表中显示的内容就可以是查询结果了。
对于分组报表,也可以这样:
如:
PrivateSubCommand11_Click()
OnErrorResumeNext
'DimsqlAsString
'sql="select*fromsaledategroupby分组字段名"
IfDataEnvironment1.command4_分组.StateadStateClosedThen
DataEnvironment1.rsCommand4_分组.Close
EndIf
IfRight$(Trim$(App.Path),1)=""Then
DataEnvironment1.Connection1.OpenApp.Path&"jxck.mdb"
Else
DataEnvironment1.Connection1.OpenApp.Path&"jxck.mdb"
EndIf
DataEnvironment1.rsCommand4.Opensql
SetDataReport4.DataSource=DataEnvironment1
DataReport4.DataMember="command4_分组"
'DataReport1.Title="出库明细总表"
DataReport4.Show
EndSub
注意要在SQL语句中含有分组关建字"groupby"就可以了。
以上代码对于要改变DataEnvironment中的记录集同样适用.
以上代码在VB6.0,Win98上调试通过.
如有问题请与我联系.
张振兴(星云)
邮箱:xingyun0615@sina.com
Oicq:4487877->