标题:如何简化优化代码
取消只看楼主
yuk_yu
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:334
专家分:134
注 册:2009-3-16
结帖率:85.71%
已结贴  问题点数:20 回复次数:2 
如何简化优化代码
程序代码:
    If Me.Combo1(0) <> "" And Me.Combo1(1) <> "" And Me.Combo1(2) <> "" And Me.Combo1(3) <> "" Then
        SQL = "select * from DataList"
        SQL = SQL + " where [UploadSN] ='" & Me.Combo1(0) & "' and [BuyerName] ='" & Me.Combo1(1) & "' and [MaterialPart] ='" & Me.Combo1(2) & "' and [YesOrNo] ='" & Me.Combo1(3) & "'"

    ElseIf Me.Combo1(0) <> "" And Me.Combo1(1) = "" And Me.Combo1(2) = "" And Me.Combo1(3) = "" Then
        SQL = "select * from DataList where [UploadSN] ='" & Me.Combo1(0) & "' "

    ElseIf Me.Combo1(0) <> "" And Me.Combo1(1) <> "" And Me.Combo1(2) = "" And Me.Combo1(3) = "" Then
        SQL = "select * from DataList where [UploadSN] ='" & Me.Combo1(0) & "' and [BuyerName] ='" & Me.Combo1(1) & "' "

    ElseIf Me.Combo1(0) <> "" And Me.Combo1(1) <> "" And Me.Combo1(2) <> "" And Me.Combo1(3) = "" Then
        SQL = "select * from DataList where [UploadSN] ='" & Me.Combo1(0) & "' and [BuyerName] ='" & Me.Combo1(1) & "' and [MaterialPart] ='" & Me.Combo1(2) & "' "

    ElseIf Me.Combo1(0) = "" And Me.Combo1(1) = "" And Me.Combo1(2) = "" And Me.Combo1(3) <> "" Then
        SQL = "select * from DataList where [YesOrNo] ='" & Me.Combo1(3) & "'"

    ElseIf Me.Combo1(0) = "" And Me.Combo1(1) = "" And Me.Combo1(2) <> "" And Me.Combo1(3) <> "" Then
        SQL = "select * from DataList where [MaterialPart] ='" & Me.Combo1(2) & "' and [YesOrNo] ='" & Me.Combo1(3) & "'"

    ElseIf Me.Combo1(0) = "" And Me.Combo1(1) <> "" And Me.Combo1(2) <> "" And Me.Combo1(3) <> "" Then
        SQL = "select * from DataList where [BuyerName] ='" & Me.Combo1(1) & "' and [MaterialPart] ='" & Me.Combo1(2) & "' and [YesOrNo] ='" & Me.Combo1(3) & "'"

    ElseIf Me.Combo1(0) <> "" And Me.Combo1(1) = "" And Me.Combo1(2) <> "" And Me.Combo1(3) = "" Then
        SQL = "select * from DataList"
        SQL = SQL + " where [UploadSN] ='" & Me.Combo1(0) & "' and [MaterialPart] ='" & Me.Combo1(2) & "'"
    ElseIf Me.Combo1(0) = "" And Me.Combo1(1) = "" And Me.Combo1(2) <> "" And Me.Combo1(3) = "" Then
        SQL = "select * from DataList"
        SQL = SQL + " where [MaterialPart] ='" & Me.Combo1(2) & "'"

    ElseIf Me.Combo1(0) <> "" And Me.Combo1(1) = "" And Me.Combo1(2) = "" And Me.Combo1(3) <> "" Then
        SQL = "select * from DataList"
        If Me.Combo1(3).Text = "Null" Then
            SQL = SQL + " where [UploadSN] ='" & Me.Combo1(0) & "' and [YesOrNo] is null"
        Else
            SQL = SQL + " where [UploadSN] ='" & Me.Combo1(0) & "' and [YesOrNo] ='" & Me.Combo1(3) & "'"
        End If

    ElseIf Me.Combo1(0) = "" And Me.Combo1(1) = "" And Me.Combo1(2) = "" And Me.Combo1(3) = "" Then
        MsgBox "Pls selct one condition", vbCritical, "Caution"
        Exit Sub
    End If
搜索更多相关主题的帖子: 如何 
2014-03-25 17:04
yuk_yu
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:334
专家分:134
注 册:2009-3-16
得分:0 
回复 2楼 lowxiong
谢谢版主
2014-03-25 18:44
yuk_yu
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:334
专家分:134
注 册:2009-3-16
得分:0 
回复 4楼 风吹过b
谢谢斑竹,太厉害了,学习ing...
2014-03-26 15:07



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




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

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