7,763
社区成员
发帖
与我相关
我的任务
分享
'拼出SQL的where条件:
If cmbField1.Text <> "" And Trim(txtValue1.Text) <> "" Then
Filed1 = " and " & cmbbracket11.Text & "[" & cmbField1.Text & "] = '" & Trim(txtValue1.Text) & "' " & cmbbracket12.Text
End If
If cmbField2.Text <> "" And Trim(txtValue2.Text) <> "" Then
Filed2 = " " & cmbAndOr1.Text & " " & cmbbracket21.Text & "[" & cmbField2.Text & "] = '" & Trim(txtValue2.Text) & "' " & cmbbracket22.Text
End If
If cmbField3.Text <> "" And Trim(txtValue3.Text) <> "" Then
Filed3 = " " & cmbAndOr2.Text & " " & cmbbracket31.Text & "[" & cmbField3.Text & "] = '" & Trim(txtValue3.Text) & "' " & cmbbracket32.Text
End If
If Filed1 <> "" Or Filed2 <> "" Or Filed3 <> "" Then
FiledTotal = " and (1=1 " & Filed1 & Filed2 & Filed3 & ")"
End If
If (cmbField1.Text <> "" And Trim(txtValue1.Text) <> "" And cmbbracket11.Text <> "" And cmbbracket12.Text = "") Or (cmbField1.Text <> "" And Trim(txtValue1.Text) <> "" And cmbbracket11.Text = "" And cmbbracket12.Text <> "") Then
MsgBox "左右括号必须成对出现!", vbExclamation, "Warning Info"
If cmbbracket11.Text = "" Then cmbbracket11.SetFocus
If cmbbracket12.Text = "" Then cmbbracket12.SetFocus
Exit Sub
End If
If (cmbField2.Text <> "" And Trim(txtValue2.Text) <> "" And cmbbracket21.Text <> "" And cmbbracket22.Text = "") Or (cmbField2.Text <> "" And Trim(txtValue2.Text) <> "" And cmbbracket21.Text = "" And cmbbracket22.Text <> "") Then
MsgBox "左右括号必须成对出现!", vbExclamation, "Warning Info"
If cmbbracket21.Text = "" Then cmbbracket21.SetFocus
If cmbbracket22.Text = "" Then cmbbracket22.SetFocus
Exit Sub
End If
If (cmbField3.Text <> "" And Trim(txtValue3.Text) <> "" And cmbbracket31.Text <> "" And cmbbracket32.Text = "") Or (cmbField3.Text <> "" And Trim(txtValue3.Text) <> "" And cmbbracket31.Text = "" And cmbbracket32.Text <> "") Then
MsgBox "左右括号必须成对出现!", vbExclamation, "Warning Info"
If cmbbracket31.Text = "" Then cmbbracket31.SetFocus
If cmbbracket32.Text = "" Then cmbbracket32.SetFocus
Exit Sub
End If
'拼出SQL的where条件:
If cmbField1.Text <> "" And Trim(txtValue1.Text) <> "" Then
Filed1 = " and " & cmbbracket11.Text & "[" & cmbField1.Text & "] = '" & Trim(txtValue1.Text) & "' " & cmbbracket12.Text
End If
If cmbField2.Text <> "" And Trim(txtValue2.Text) <> "" Then
Filed2 = " " & cmbAndOr1.Text & " " & cmbbracket21.Text & "[" & cmbField2.Text & "] = '" & Trim(txtValue2.Text) & "' " & cmbbracket22.Text
End If
If cmbField3.Text <> "" And Trim(txtValue3.Text) <> "" Then
Filed3 = " " & cmbAndOr2.Text & " " & cmbbracket31.Text & "[" & cmbField3.Text & "] = '" & Trim(txtValue3.Text) & "' " & cmbbracket32.Text
End If
If Filed1 <> "" Or Filed2 <> "" Or Filed3 <> "" Then
FiledTotal = " and (1=1 " & Filed1 & Filed2 & Filed3 & ")"
End If
Function CheckBracket(ParamArray bracket()) As Boolean
Dim iBarcket As Long
Dim cbo As ComboBox
Dim i As Long
For i = 0 To UBound(bracket)
Set cbo = bracket(i)
Select Case cbo.Text
Case "("
iBarcket = iBarcket + 1
Case ")"
iBarcket = iBarcket - 1
If iBarcket < 0 Then
MsgBox "不能先出现右括号!", vbExclamation, "Warning Info"
cbo.SetFocus
Exit Function
End If
End Select
Next
If iBarcket <> 0 Then
MsgBox "左右括号必须成对出现!", vbExclamation, "Warning Info"
Exit Function
End If
CheckBoxConstants = True
End Function
'调用
If Not CheckBracket(cmbbracket11, cmbbracket12, _
cmbbracket21, cmbbracket22, _
cmbbracket31, cmbbracket32) Then
Exit Sub
End If