求助~
此功能是为了从三个cmbox控件中获得参数进行帅选的操作 而操作的参数有多种组合?但现在的问题是第一组和最后一组select可以执行其他的没有反应 ,不存在数据表中数据的问题,希望告诉解决!temp_order用于记录上一次是按照升序还系降序来排列搜索给过的 默认给了1的数值
Private Sub Command1_Click()
Dim strsql_tongji As String
Dim rr As New ADODB.Recordset
If Combo1.Text = "" And Combo2.Text = "" And Combo3.Text = "" Then '检验参数输入是否符合要求
MsgBox "请输入统计参数!"
Exit Sub
End If
If Combo1.Text = "" Then '按月和 部门查找
if temp_order = 0 Then ’判断是用升序还是用降序来显示结果
strsql_tongji = "select * from 出勤统计 where 月=" & y & " and 部门='" & z & "' order by 年 desc"
temp_order = 1
Else: strsql_tongji = "select * from 出勤统计 where 月=" & y & " and 部门='" & z & "' order by 年 asc"
temp_order = 0
End If
ElseIf Combo2.Text = "" Then '按年和部门查找
If temp_order = 0 Then
strsql_tongji = "select * from 出勤统计 where 年=" & x & " and 部门='" & z & "' order by 月 desc"
temp_order = 1
Else: strsql_tongji = "select * from 出勤统计 where 年=" & x & " and 部门='" & z & "' order by 月 asc"
temp_order = 0
End If
ElseIf Combo3.Text = "" Then '按年和月查找
If temp_order = 0 Then
strsql_tongji = "select * from 出勤统计 where 年=" & x & " and 月=" & y & " order by 部门 desc "
temp_order = 1
Else: strsql_tongji = "select * from 出勤统计 where 年=" & x & " and 月=" & y & " order by 部门 asc"
temp_order = 0
End If
ElseIf Combo1.Text = "" And Combo2.Text = "" Then '按部门查找
If temp_order = 0 Then
strsql_tongji = "select * from 出勤统计 where 部门='" & z & "' order by 年 desc,月 desc"
temp_order = 1
Else: strsql_tongji = "select * from 出勤统计 where 部门='" & z & "' order by 年 asc,月 asc"
temp_order = 0
End If
ElseIf Combo1.Text = "" And Combo3.Text = "" Then '按月查找
If temp_order = 0 Then
strsql_tongji = "select * from 出勤统计 where 月=" & y & " order by 部门 desc ,年 desc"
temp_order = 1
Else: strsql_tongji = "select * from 出勤统计 where 月=" & y & " order by 部门 asc, 年 asc"
temp_order = 0
End If
ElseIf Combo2.Text = "" And Combo3.Text = "" Then '按年查找
If temp_order = 0 Then
strsql_tongji = "select * from 出勤统计 where 年=" & x & " order by 部门 desc ,月 desc"
temp_order = 1
Else: strsql_tongji = "select * from 出勤统计 where 年=" & x & " order by 部门 asc,月 asc"
temp_order = 0
End If
Else
If temp_order = 0 Then
strsql_tongji = "select * from 出勤统计 where 年=" & x & " and 月=" & y & " and 部门='" & z & "' order by 部门 desc ,年 desc,月 desc"
temp_order = 1
Else: strsql_tongji = "select * from 出勤统计 where 年=" & x & " and 月=" & y & " and 部门='" & z & "' order by 部门 asc, 年 asc,月 asc"
temp_order = 0
End If
End If
rr.Open strsql_tongji, conn, adOpenKeyset, adLockReadOnly
Set DataGrid1.DataSource = rr
DataGrid1.Refresh
End Sub