我写段程序,按条件打印报表,我一选按日期查询,查询出结果后,点打印想调出打印报表页面,就显示错误: 实时错误'3705' 对象打开时不允许操作.
代码:
Private Sub CmdPrint_Click()
    Select Case Combo2.text
  Case Is = "like"
    If Check1.Value = 0 And Check2.Value = 1 Then
       DataE1.rsCommand1.Open "select * from Student where Student." + Combo1.text + " like +'" + Text1.text + "'+ '%'order by 编号", Cnn, adOpenKeyset, adLockOptimistic
    End If
    If Check1.Value = 1 And Check2.Value = 0 Then
       DataE1.rsCommand1.Open "Select * from Student where 日期 between " + Chr(35) + Str(DTP1.Value) + Chr(35) + "and " + Chr(35) + Str(DTP2.Value) + Chr(35) + "order by 编号", Cnn, adOpenKeyset, adLockOptimistic
    End If
    If Check1.Value = 1 And Check2.Value = 1 Then
       DataE1.rsCommand1.Open "select * from Student where Student." & Combo1.text & " " & " like +'" + Text1.text + "'+ '%'and 日期 between " + Chr(35) + Str(DTP1.Value) + Chr(35) + "and " + Chr(35) + Str(DTP2.Value) + Chr(35) + "order by 编号", Cnn, adOpenKeyset, adLockOptimistic
    End If
  Case Is = "="
    If Check1.Value = 0 And Check2.Value = 1 Then
       DataE1.rsCommand1.Open "select * from Student where Student." & Combo1.text & " " & "= '" + Text1.text + "'order by 编号"
    End If
    If Check1.Value = 1 And Check2.Value = 1 Then
       DataE1.rsCommand1.Open "select * from Student where Student." & Combo1.text & " " & " ='" + Text1.text + "'and 日期 between " + Chr(35) + Str(DTP1.Value) + Chr(35) + "and " + Chr(35) + Str(DTP2.Value) + Chr(35) + "order by 编号", Cnn, adOpenKeyset, adLockOptimistic
    End If
 End Select
 DR1_bysxxcx.Show
End Sub其中的错误代码:
If Check1.Value = 1 And Check2.Value = 0 Then
       DataE1.rsCommand1.Open "Select * from Student where 日期 between " + Chr(35) + Str(DTP1.Value) + Chr(35) + "and " + Chr(35) + Str(DTP2.Value) + Chr(35) + "order by 编号", Cnn, adOpenKeyset, adLockOptimistic
    End If
其中凡是设计到日期查询的代码都在查询过后发生上面的错误!!高手帮忙看看哪里出错!!谢谢

解决方案 »

  1.   

    其中的错误代码:
    If Check1.Value = 1 And Check2.Value = 0 Then
           DataE1.rsCommand1.Open "Select * from Student where 日期 between " + Chr(35) + Str(DTP1.Value) + Chr(35) + "and " + Chr(35) + Str(DTP2.Value) + Chr(35) + "order by 编号", Cnn, adOpenKeyset, adLockOptimistic
        End If
    ---------------------------------------------------------
    多次打开记录集出现的错误,在打开前先将记录集关闭就行了:其中的错误代码:
    If Check1.Value = 1 And Check2.Value = 0 Then
           If DataE1.rsCommand1.State=adStateOpen Then DataE1.rsCommand1.Close  '<-----------加上这句
           DataE1.rsCommand1.Open "Select * from Student where 日期 between " + Chr(35) + Str(DTP1.Value) + Chr(35) + "and " + Chr(35) + Str(DTP2.Value) + Chr(35) + "order by 编号", Cnn, adOpenKeyset, adLockOptimistic
        End If
      

  2.   

    Private Sub CmdPrint_Click()
        If DataE1.rsCommand1.State = adStateOpen Then DataE1.rsCommand1.Close '<-----------加上这句
        Select Case Combo2.Text
      Case Is = "like"
        If Check1.Value = 0 And Check2.Value = 1 Then
           DataE1.rsCommand1.Open "select * from Student where Student." + Combo1.Text + " like +'" + Text1.Text + "'+ '%'order by 编号", Cnn, adOpenKeyset, adLockOptimistic
        End If
        If Check1.Value = 1 And Check2.Value = 0 Then
           DataE1.rsCommand1.Open "Select * from Student where 日期 between " + Chr(35) + Str(DTP1.Value) + Chr(35) + "and " + Chr(35) + Str(DTP2.Value) + Chr(35) + "order by 编号", Cnn, adOpenKeyset, adLockOptimistic
        End If
        If Check1.Value = 1 And Check2.Value = 1 Then
           DataE1.rsCommand1.Open "select * from Student where Student." & Combo1.Text & " " & " like +'" + Text1.Text + "'+ '%'and 日期 between " + Chr(35) + Str(DTP1.Value) + Chr(35) + "and " + Chr(35) + Str(DTP2.Value) + Chr(35) + "order by 编号", Cnn, adOpenKeyset, adLockOptimistic
        End If
      Case Is = "="
        If Check1.Value = 0 And Check2.Value = 1 Then
           DataE1.rsCommand1.Open "select * from Student where Student." & Combo1.Text & " " & "= '" + Text1.Text + "'order by 编号"
        End If
        If Check1.Value = 1 And Check2.Value = 1 Then
           DataE1.rsCommand1.Open "select * from Student where Student." & Combo1.Text & " " & " ='" + Text1.Text + "'and 日期 between " + Chr(35) + Str(DTP1.Value) + Chr(35) + "and " + Chr(35) + Str(DTP2.Value) + Chr(35) + "order by 编号", Cnn, adOpenKeyset, adLockOptimistic
        End If
     End Select
     DR1_bysxxcx.Show
    End Sub