查询打印的错误????

xxd88 2006-02-11 09:28:04
我写段程序,按条件打印报表,我一选按日期查询,查询出结果后,点打印想调出打印报表页面,就显示错误: 实时错误'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
其中凡是设计到日期查询的代码都在查询过后发生上面的错误!!高手帮忙看看哪里出错!!谢谢
...全文
65 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xxd88 2006-02-11
  • 打赏
  • 举报
回复
谢谢楼上的兄弟!
faysky2 2006-02-11
  • 打赏
  • 举报
回复
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
faysky2 2006-02-11
  • 打赏
  • 举报
回复
其中的错误代码:
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

1,217

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧