我是通过数据环境设计器来做数据库连接的。在做报表输出时,为什么输出的记录不是我选择条件后的记录,但后台数据库中表的记录却是正确的。我是用VB自带的报表设计器做的。代码如下:
Private Sub cmdOk_Click()
strwhere = ""
rs.CursorType = adOpenStatic
rs.CursorLocation = adUseClient
rs.LockType = adLockOptimistic ' adLockPessimistic
strsql = "delete * from temp_sql"
cm.CommandType = adCmdText
cm.CommandText = strsql
cm.Execute
strsql = "insert into temp_sql select curdate ,depart_name ," & _
"file_name,paper_type,paper_num,people,kind from total where "
'在此编写如果没有选择任何条件下的打印程序,即打印所有记录!
If optRept.Item(0).Value = True Then
If chkType.Item(0).Value = 1 Then
strwhere = "kind='" & chkType.Item(0).Caption & "'"
End If
If chkType.Item(1).Value = 1 Then
If strwhere = "" Then
strwhere = "kind='" & chkType.Item(1).Caption & "'"
Else
strwhere = strwhere & " or kind='" & chkType.Item(1).Caption & "'"
End If
End If
strsql = strsql & strwhere
cm.CommandType = adCmdText
cm.CommandText = strsql
cm.Execute
datrep.Show
End If
End Sub
Private Sub cmdOk_Click()
strwhere = ""
rs.CursorType = adOpenStatic
rs.CursorLocation = adUseClient
rs.LockType = adLockOptimistic ' adLockPessimistic
strsql = "delete * from temp_sql"
cm.CommandType = adCmdText
cm.CommandText = strsql
cm.Execute
strsql = "insert into temp_sql select curdate ,depart_name ," & _
"file_name,paper_type,paper_num,people,kind from total where "
'在此编写如果没有选择任何条件下的打印程序,即打印所有记录!
If optRept.Item(0).Value = True Then
If chkType.Item(0).Value = 1 Then
strwhere = "kind='" & chkType.Item(0).Caption & "'"
End If
If chkType.Item(1).Value = 1 Then
If strwhere = "" Then
strwhere = "kind='" & chkType.Item(1).Caption & "'"
Else
strwhere = strwhere & " or kind='" & chkType.Item(1).Caption & "'"
End If
End If
strsql = strsql & strwhere
cm.CommandType = adCmdText
cm.CommandText = strsql
cm.Execute
datrep.Show
End If
End Sub
Private Sub DataReport_QueryClose(Cancel As Integer, CloseMode As Integer)
If dataTuring.rsrptStockChangeOrders.State = adStateOpen Then dataTuring.rsrptStockChangeOrders.Close
End Sub