我在做报表输出时(用的是VB自带的设计器),为什么在输出时的记录与我选择条件后的记录不一致,但后台库中表的记录却是我想得到的。代码如下:Private Sub cmdOk_Click()
strwhere = ""
Set rs = New ADODB.Recordset
Set cm = New ADODB.Command
cm.ActiveConnection = DEfirst.Confirst
rs.CursorType = adOpenStatic
rs.CursorLocation = adUseClient
rs.LockType = 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
'Debug.Print chkType.Item(0).Value
End If
End Sub
strwhere = ""
Set rs = New ADODB.Recordset
Set cm = New ADODB.Command
cm.ActiveConnection = DEfirst.Confirst
rs.CursorType = adOpenStatic
rs.CursorLocation = adUseClient
rs.LockType = 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
'Debug.Print chkType.Item(0).Value
End If
End Sub
set m_rs=cm.execute
set datrep.datasource=m_rs
用这个方法试一试
请知道的朋友告诉我,谢谢!!!!