查询打印的错误????

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
其中凡是设计到日期查询的代码都在查询过后发生上面的错误!!高手帮忙看看哪里出错!!谢谢
...全文
36 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过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

回复
相关推荐
发帖

1188

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
帖子事件
创建了帖子
2006-02-11 09:28
社区公告
暂无公告