今天做报表出了这种现象:
if ??? then
set rs=cn.excute("sql语句")
else
set rs=cn.excute("sql语句")
Set DR8.DataSource = rs当符合第一个条件时,总是弹出"一般错误"
另一种就可以,请大家猜测一下呀,sql语句测试过没有问题!!!!
if ??? then
set rs=cn.excute("sql语句")
else
set rs=cn.excute("sql语句")
Set DR8.DataSource = rs当符合第一个条件时,总是弹出"一般错误"
另一种就可以,请大家猜测一下呀,sql语句测试过没有问题!!!!
Private Sub DataReport_Initialize()
DR7.Orientation = rptOrientLandscape
Dim cn As New ADODB.Connection
cn.Open "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=sql_ado1_bw"
Dim rs As New ADODB.Recordset
Select Case flag_report_h
Case "1" '工号为空 '****错误?????????????????????****
Set rs = cn.Execute("select a.工号,b.姓名 ,c.部门名称,a.日期,a.请假开始日期时间,a.请假结束日期时间,a.请假时数,a.年休假,a.事假,a.病假,a.婚假,a.产假,a.其它,a.备注 from holidays a,employee b,department c where a.工号=b.工号 and b.部门代号=c.部门代号 and 年休假='0' and 日期>='" + CStr(Form2.DTP1.Value) + "' and 日期<='" + CStr(Form2.DTP2.Value) + "'")
Case "2" '工号不为空 **************************************正确*****
Set rs = cn.Execute("select a.工号,b.姓名 ,c.部门名称,a.日期,a.请假开始日期时间,a.请假结束日期时间,a.请假时数,a.年休假 ,a.事假,a.病假,a.婚假,a.产假,a.其它,a.备注 from holidays a,employee b,department c where a.工号=b.工号 and b.部门代号=c.部门代号 and 年休假='0' and (a.工号='" + Trim(Form2.Text1.Text) + "') and 日期>='" + CStr(Form2.DTP1.Value) + "' and 日期<='" + CStr(Form2.DTP2.Value) + "'")
End Select
Set DR7.DataSource = rsDR7.Sections.Item("section1").Controls("Text1").DataField = rs.Fields(0).Name
DR7.Sections.Item("Section1").Controls("Text2").DataField = rs.Fields(1).Name
DR7.Sections.Item("Section1").Controls("Text3").DataField = rs.Fields(2).Name
DR7.Sections.Item("Section1").Controls("Text4").DataField = rs.Fields(3).Name
DR7.Sections.Item("Section1").Controls("Text5").DataField = rs.Fields(4).Name
DR7.Sections.Item("Section1").Controls("Text6").DataField = rs.Fields(5).Name
DR7.Sections.Item("Section1").Controls("Text7").DataField = rs.Fields(6).Name
DR7.Sections.Item("Section1").Controls("Text8").DataField = rs.Fields(7).Name
DR7.Sections.Item("Section1").Controls("Text9").DataField = rs.Fields(8).Name
DR7.Sections.Item("Section1").Controls("Text10").DataField = rs.Fields(9).Name
DR7.Sections.Item("Section1").Controls("Text11").DataField = rs.Fields(10).Name
DR7.Sections.Item("Section1").Controls("Text12").DataField = rs.Fields(11).Name
DR7.Sections.Item("Section1").Controls("Text13").DataField = rs.Fields(12).Name
DR7.Sections.Item("Section1").Controls("Text14").DataField = rs.Fields(13).NameDR7.Sections(1).Controls("Label4").Caption = Form2.DTP1.Value
DR7.Sections(1).Controls("Label6").Caption = Form2.DTP2.Value
DR7.Sections(4).Controls("label8").Caption = "第%p页共%P页"
End Sub
Private Sub DataReport_Initialize()
DR8.Orientation = rptOrientLandscape
Dim cn As New ADODB.Connection
cn.Open "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=sql_ado1_bw"
Dim rs As New ADODB.Recordset
MsgBox flag_report_f
Select Case flag_report_f Case "1" ' '工号为空 '****错误?????????????????????****
Set rs = cn.Execute("select a.工号,b.姓名,c.部门名称,a.日期,a.时段,a.时间1,a.时间2,a.操作工号,a.备注 from forget a ,employee b ,department c where a.工号=b.工号 and b.部门代号=c.部门代号 ")
'Set rs = cn.Execute("select f.工号,b.姓名 ,c.部门名称,f.日期,f.时段,f.时间1,f.时间2,f.操作工号,f.备注 from forget f ,employee b,department c where (f.工号=b.工号) and (b.部门代号=c.部门代号) and (日期>='" + CStr(Form2.DTP1.Value) + "') and (日期<='" + CStr(Form2.DTP2.Value) + "')")
'Form2.Text3.Text = "select a.工号,b.姓名 ,c.部门名称,a.日期,a.时段,a.时间1,a.时间2,a.操作工号,a.备注 from forget a ,employee b,department c where a.工号=b.工号 and b.部门代号=c.部门代号 and 日期>='" + CStr(Form2.DTP1.Value) + "' and 日期<='" + CStr(Form2.DTP2.Value) + "'"
Case "2" ' '工号不为空 **************************************正确
Set rs = cn.Execute("select a.工号,b.姓名 ,c.部门名称,a.日期,a.时段,a.时间1,a.时间2,a.操作工号,a.备注 from forget a,employee b,department c where a.工号=b.工号 and b.部门代号=c.部门代号 and (a.工号='" + Trim(Form2.Text1.Text) + "') and 日期>='" + CStr(Form2.DTP1.Value) + "' and 日期<='" + CStr(Form2.DTP2.Value) + "'")
End Select
Set DR8.DataSource = rsDR8.Sections.Item("section1").Controls("Text1").DataField = rs.Fields(0).Name
DR8.Sections.Item("Section1").Controls("Text2").DataField = rs.Fields(1).Name
DR8.Sections.Item("Section1").Controls("Text3").DataField = rs.Fields(2).Name
DR8.Sections.Item("Section1").Controls("Text4").DataField = rs.Fields(3).Name
DR8.Sections.Item("Section1").Controls("Text5").DataField = rs.Fields(4).Name
DR8.Sections.Item("Section1").Controls("Text6").DataField = rs.Fields(5).Name
DR8.Sections.Item("Section1").Controls("Text7").DataField = rs.Fields(6).Name
DR8.Sections.Item("Section1").Controls("Text8").DataField = rs.Fields(7).Name
DR8.Sections.Item("Section1").Controls("Text9").DataField = rs.Fields(8).Name
DR8.Sections(1).Controls("Label4").Caption = Form2.DTP1.Value
DR8.Sections(1).Controls("Label6").Caption = Form2.DTP2.Value
DR8.Sections(4).Controls("label8").Caption = "第%p页共%P页"
End Sub
Private Sub DataReport_Initialize()
DR8.Orientation = rptOrientLandscape
Dim cn As New ADODB.Connection
cn.Open "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=sql_ado1_bw"
Dim rs As New ADODB.Recordset
MsgBox flag_report_f
Select Case flag_report_f Case "1" '工号为空 ***错误***
Set rs = cn.Execute("select a.工号,b.姓名,c.部门名称,a.日期,a.时段,a.时间1,a.时间2,a.操作工号,a.备注 from forget a ,employee b ,department c where a.工号=b.工号 and b.部门代号=c.部门代号 ")
Case "2" '工号不为空 ***正确**
Set rs = cn.Execute("select a.工号,b.姓名 ,c.部门名称,a.日期,a.时段,a.时间1,a.时间2,a.操作工号,a.备注 from forget a,employee b,department c where a.工号=b.工号 and b.部门代号=c.部门代号 and (a.工号='" + Trim(Form2.Text1.Text) + "') and 日期>='" + CStr(Form2.DTP1.Value) + "' and 日期<='" + CStr(Form2.DTP2.Value) + "'")
End Select
Set DR8.DataSource = rsDR8.Sections.Item("section1").Controls("Text1").DataField = rs.Fields(0).Name
DR8.Sections.Item("Section1").Controls("Text2").DataField = rs.Fields(1).Name
DR8.Sections.Item("Section1").Controls("Text3").DataField = rs.Fields(2).Name
DR8.Sections.Item("Section1").Controls("Text4").DataField = rs.Fields(3).Name
DR8.Sections.Item("Section1").Controls("Text5").DataField = rs.Fields(4).Name
DR8.Sections.Item("Section1").Controls("Text6").DataField = rs.Fields(5).Name
DR8.Sections.Item("Section1").Controls("Text7").DataField = rs.Fields(6).Name
DR8.Sections.Item("Section1").Controls("Text8").DataField = rs.Fields(7).Name
DR8.Sections.Item("Section1").Controls("Text9").DataField = rs.Fields(8).Name
DR8.Sections(1).Controls("Label4").Caption = Form2.DTP1.Value
DR8.Sections(1).Controls("Label6").Caption = Form2.DTP2.Value
DR8.Sections(4).Controls("label8").Caption = "第%p页共%P页"
End Sub