Foxtable(狐表)用户栏目专家坐堂 → [求助]简化代码


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

主题:[求助]简化代码

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


加好友 发短信
等级:幼狐 帖子:163 积分:1306 威望:0 精华:0 注册:2015/6/11 22:37:00
[求助]简化代码  发帖心情 Post By:2015/8/1 12:42:00 [只看该作者]

With Tables("台账查询_table1")
    If e.Form.Controls("ComboBox1").text = "" And e.Form.Controls("DateTimePicker1").text ="" And e.Form.Controls("DateTimePicker2").text ="" And e.Form.Controls("DropBox1").text ="" Then
        .filter =""
    Else
        If e.Form.Controls("ComboBox1").text = "" And e.Form.Controls("DateTimePicker1").text ="" And e.Form.Controls("DateTimePicker2").text ="" Then
            .filter = "品号 = '" & e.Form.Controls("DropBox1").text & "' "
        Else
            If e.Form.Controls("DateTimePicker1").text ="" And e.Form.Controls("DateTimePicker2").text ="" And e.Form.Controls("DropBox1").text ="" Then
                .filter = "仓库 = '" & e.Form.Controls("ComboBox1").text & "' "
            Else
                If  e.Form.Controls("ComboBox1").text = "" And e.Form.Controls("DateTimePicker2").text ="" And e.Form.Controls("DropBox1").text ="" Then
                    .filter ="日期 >= #" &e.Form.Controls("DateTimePicker1").text & "# "
                Else
                    If  e.Form.Controls("ComboBox1").text = "" And e.Form.Controls("DateTimePicker1").text ="" And e.Form.Controls("DropBox1").text ="" Then
                        .filter = "日期 <= #" & e.Form.Controls("DateTimePicker2").text & "# "
                    Else
                        If e.Form.Controls("DateTimePicker1").text ="" And e.Form.Controls("DateTimePicker2").text ="" Then
                           
                            .filter = "仓库 = '" & e.Form.Controls("ComboBox1").text & "'and 品号 ='" & e.Form.Controls("DropBox1").text & "' "
                        Else
                            If e.Form.Controls("DropBox1").text="" And e.Form.Controls("DateTimePicker1").text="" Then
                                .filter = "仓库 = '" & e.Form.Controls("ComboBox1").text & "' and 日期 <= #" & e.Form.Controls("DateTimePicker2").text & "# "
                            Else
                                If e.Form.Controls("DateTimePicker2").text="" And e.Form.Controls("DropBox1").text="" Then
                                    .filter = "仓库 = '" & e.Form.Controls("ComboBox1").text & "' and 日期 >= #" & e.Form.Controls("DateTimePicker1").text & "# "
                                Else
                                    If e.Form.Controls("DropBox1").text ="" And e.Form.Controls("ComboBox1").text="" Then
                                        .filter ="日期 >= #" &e.Form.Controls("DateTimePicker1").text & "# and 日期 <= #" & e.Form.Controls("DateTimePicker2").text & "# "
                                    Else
                                        If e.Form.Controls("DateTimePicker1").text="" And e.Form.Controls("ComboBox1").text="" Then
                                            .filter = "日期 <= #" & e.Form.Controls("DateTimePicker2").text & "# and 品号 ='" & e.Form.Controls("DropBox1").text & "' "
                                        Else
                                            If e.Form.Controls("DateTimePicker1").text="" And e.Form.Controls("ComboBox1").text="" Then
                                                .filter = "日期 >= #" & e.Form.Controls("DateTimePicker1").text & "# and 品号 ='" & e.Form.Controls("DropBox1").text & "' "
                                            Else
                                               
                                               
                                                If e.Form.Controls("DropBox1").text ="" Then
                                                    .filter = "仓库 = '" & e.Form.Controls("ComboBox1").text & "' and 日期 >= #" &e.Form.Controls("DateTimePicker1").text & "# and 日期<= #" & e.Form.Controls("DateTimePicker2").text & "# "
                                                Else
                                                    If e.Form.Controls("ComboBox1").text = "" Then
                                                        .filter = "日期 >= #" &e.Form.Controls("DateTimePicker1").text & "# and 日期<= #" & e.Form.Controls("DateTimePicker2").text & "# and 品号 = '" & e.Form.Controls("DropBox1").text & "' "
                                                    Else
                                                        If e.Form.Controls("DateTimePicker1").text="" Then
                                                            .filter = "仓库 = '" & e.Form.Controls("ComboBox1").text & "' and 日期<= #" & e.Form.Controls("DateTimePicker2").text & "# and 品号 = '" & e.Form.Controls("DropBox1").text & "' "
                                                           
                                                        Else
                                                            If e.Form.Controls("DateTimePicker2").text="" Then
                                                                .filter = "仓库 = '" & e.Form.Controls("ComboBox1").text & "' and 日期 >= #" &e.Form.Controls("DateTimePicker1").text & "# and 品号 = '" & e.Form.Controls("DropBox1").text & "' "
                                                            Else
                                                                .filter = "仓库 = '" & e.Form.Controls("ComboBox1").text & "' and 日期 >= #" &e.Form.Controls("DateTimePicker1").text & "# and 日期<= #" & e.Form.Controls("DateTimePicker2").text & "# and 品号 = '" & e.Form.Controls("DropBox1").text & "' "
                                                            End If
                                                        End If
                                                    End If
                                                End If
                                            End If
                                        End If
                                    End If
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        End If
    End If

End With

 

那位大神能帮忙简化下代码


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


加好友 发短信
等级:狐神 帖子:4752 积分:34568 威望:0 精华:0 注册:2008/8/31 22:44:00
  发帖心情 Post By:2015/8/1 13:09:00 [只看该作者]


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


加好友 发短信
等级:版主 帖子:1693 积分:12135 威望:0 精华:7 注册:2013/7/11 10:52:00
  发帖心情 Post By:2015/8/1 13:45:00 [只看该作者]

Dim filter As String  = ""
If e.Form.Controls("ComboBox1").text > ""  Then  filter = "仓库 = '" & e.Form.Controls("ComboBox1").text & "' "
If e.Form.Controls("DateTimePicker1").text >"" Then  filter =filter & " And 日期 >= #" & e.Form.Controls("DateTimePicker1").text & "# "
If e.Form.Controls("DateTimePicker2").text >""  Then  filter =filter & " And 日期 <= #" & e.Form.Controls("DateTimePicker2").text & "#  "
If e.Form.Controls("DropBox1").text >""  Then  filter =filter & " And 品号 ='" & e.Form.Controls("DropBox1").text & "' "
filter = filter.Trim
If filter.StartsWith("And") Then  filter = filter.SubString(3)
Tables("台账查询_table1").Filter = filter

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


加好友 发短信
等级:幼狐 帖子:163 积分:1306 威望:0 精华:0 注册:2015/6/11 22:37:00
  发帖心情 Post By:2015/8/1 13:51:00 [只看该作者]

谢谢,这个好,我都写死了

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


加好友 发短信
等级:幼狐 帖子:133 积分:2273 威望:0 精华:0 注册:2008/9/1 8:41:00
  发帖心情 Post By:2015/10/16 13:44:00 [只看该作者]

学习了,另外弱弱的问一下,If filter.StartsWith("And") Then  filter = filter.SubString(3) 中,参数3是什么含义?

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


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/10/16 14:01:00 [只看该作者]

以下是引用xuebai在2015/10/16 13:44:00的发言:
学习了,另外弱弱的问一下,If filter.StartsWith("And") Then  filter = filter.SubString(3) 中,参数3是什么含义?

 

参考,从第三位开始截取所有字符

 

http://www.foxtable.com/help/topics/0240.htm

 

 

 


 回到顶部