Foxtable(狐表)用户栏目专家坐堂 → [求助]如何查询


  共有2095人关注过本帖树形打印复制链接

主题:[求助]如何查询

帅哥哟,离线,有人找我吗?
kjkui
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:18 积分:196 威望:0 精华:0 注册:2016/9/26 15:20:00
[求助]如何查询  发帖心情 Post By:2016/10/12 9:13:00 [显示全部帖子]

Dim xz As WinForm.ComboBox = e.Form.Controls("选择")
Dim btn1 As WinForm.DateTimePicker = Forms("窗口1").Controls("StartDate")
Dim btn2 As WinForm.DateTimePicker = Forms("窗口1").Controls("EndDate")
 If xz.value = "今天"
    Dim y As Integer = Date.Today.Year
    Dim d As Date = Date.Today
    btn1.value = d
    btn2.value = d
    
End If

If xz.value = "本周"
    
    Dim y As Integer = Date.Today.Year
    Dim w As Integer = Date.Today.DayOfWeek '算出今天是星期几
    Dim dt1 As Date = Date.Today.AddDays(-w) '获取本周的第一天
    Dim dt2 As Date = Date.Today.AddDays(6 - w) '获取本周的最后一天
    btn1.value = dt1
    btn2.value = dt2
   
End If    
If xz.value = "全部"
    e.Form.Controls("EndDate").Value = Nothing
    e.Form.Controls("StartDate").Value = Nothing

End If
一个下拉框有多个值,选择某个值,会出现对应的时间范围,现在的代码必须先选择“全部”,再选择其他的值才可以查询对应的值,如何修改(应该是if语句的错误??)

 回到顶部
帅哥哟,离线,有人找我吗?
kjkui
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:18 积分:196 威望:0 精华:0 注册:2016/9/26 15:20:00
  发帖心情 Post By:2016/10/12 9:23:00 [显示全部帖子]

刚刚的代码在ValueChanged事件中

其中在TextChanged事件中写的是

Dim Filter As String


With e.Form.Controls("选择")

    Dim xz As WinForm.ComboBox = e.Form.Controls("选择")   

    If xz.value = "全部"

        Tables("订单管理").ApplyFilter = False

        Dim btn3 As WinForm.DateTimePicker = Forms("窗口1").Controls("StartDate")

        Dim btn4 As WinForm.DateTimePicker = Forms("窗口1").Controls("EndDate")

        btn3.Enabled = True

        btn4.Enabled = True

        e.Form.Controls("EndDate").Value = Nothing

        e.Form.Controls("StartDate").Value = Nothing

        

        Tables("订单管理").Filter = Filter

        

    End If

    If xz.value = "今天"

        Dim y As Integer = Date.Today.Year

        Dim d As Date = Date.Today '当前时间

        Filter = "时间 = '" & d & "' And 时间 = '" & d & "'"

        Tables("订单管理").Filter = Filter

        

    End If

If xz.value = "本周"
        Dim y As Integer = Date.Today.Year
        Dim w As Integer = Date.Today.DayOfWeek '算出今天是星期几
        Dim dt1 As Date = Date.Today.AddDays(-w) '获取本周的第一天
        Dim dt2 As Date = Date.Today.AddDays(6 - w) '获取本周的最后一天
        'Dim Filter As String
        Filter = "时间 >= '" & dt1 & "' And 时间 <= '" & dt2 & "'"
        Tables("订单管理").Filter = Filter
        
    End If
End With
With e.Form.Controls("StartDate")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "时间 >= '" & .Value & "'"
    End If
End With
With e.Form.Controls("EndDate")
    If .Value IsNot Nothing Then
        If Filter >"" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "时间 <= '" & .Value & "'"
    End If
End With
If Filter > "" Then
    Tables("订单管理").Filter = Filter
End If



 回到顶部