标题:求助~
取消只看楼主
tcapple486
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2007-4-19
 问题点数:0 回复次数:1 
求助~
此功能是为了从三个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
搜索更多相关主题的帖子: 参数 帅选 Sub And 
2008-03-05 17:43
tcapple486
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2007-4-19
得分:0 
改为这个形式后只是按单个参数查找有问题 其他都ok 那个高手给我只教a
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  '按月和 部门查找
Select Case temp_order
Case 0:strsql_tongji = "select * from 出勤统计 where  月=" & y & " and 部门='" & z & "' order by 年 desc"
temp_order = 1
Case 1: strsql_tongji = "select * from 出勤统计 where  月=" & y & " and 部门='" & z & "' order by  年 asc"
        temp_order = 0

End Select

ElseIf Combo2.Text = "" Then '按年和部门查找
   Select Case temp_order
  Case 0:
  strsql_tongji = "select * from 出勤统计 where 年=" & x & "  and 部门='" & z & "' order by 月 desc"
  temp_order = 1
  Case 1: strsql_tongji = "select * from 出勤统计 where 年=" & x & " and 部门='" & z & "' order by 月 asc"
  temp_order = 0
  End Select
  
   
   ElseIf Combo3.Text = "" Then '按年和月查找
    Select Case temp_order
    Case 0: strsql_tongji = "select * from 出勤统计 where 年=" & x & " and 月=" & y & "  order by 部门 desc "
    temp_order = 1
    Case 1: strsql_tongji = "select * from 出勤统计 where 年=" & x & " and 月=" & y & "  order by 部门 asc"
    temp_order = 0
    End Select
   
     
   ElseIf Combo1.Text = "" And Combo2.Text = "" Then '按部门查找
 
     Select Case temp_order
     Case 0: strsql_tongji = "select * from 出勤统计 where  部门='" & z & "' order by 年 desc,月 desc"
     temp_order = 1
     Case 1: strsql_tongji = "select * from 出勤统计 where 部门='" & z & "' order by  年 asc,月 asc"
     temp_order = 0
     End Select
    ElseIf Combo1.Text = "" And Combo3.Text = "" Then '按月查找
      Select Case temp_order
       Case 0: strsql_tongji = "select * from 出勤统计 where 月=" & y & "  order by 部门 desc ,年 desc"
       temp_order = 1
       Case 1: strsql_tongji = "select * from 出勤统计 where  月=" & y & "  order by 部门 asc, 年 asc"
       temp_order = 0
    End Select
       ElseIf Combo2.Text = "" And Combo3.Text = "" Then '按年查找
       Select Case temp_order
        Case 0: strsql_tongji = "select * from 出勤统计 where 年=" & x & "  order by 部门 desc ,月 desc"
        temp_order = 1
     Case 1: strsql_tongji = "select * from 出勤统计 where 年=" & x & "  order by 部门 asc,月 asc"
        temp_order = 0
        End Select
        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
2008-03-05 18:12



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-202101-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.802544 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved