如何简化优化代码
程序代码:
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