Private Sub cmdOk_Click()
Dim txtSQL As String
Dim msgText As String
Dim mrc As ADODB.Recordset
txtSQL = "select * from worklog_info where " & ComboFileName1.Tag & ComboSign1.Text & "'" & txtInquire1.Text & "'" '前后对应(查询的是个语句,教之分情况方便!)
If ComboRelation1.Text <> "" Then '检查第二个组合字段
If ComboFileName2.Text = "" Then
msgbox "请选择字段名", vbOKOnly + vbExclamation, "警告"
ComboFileName2.SetFocus
' ComboFileName2.SelStart = 0
Exit Sub
End If
If ComboSign2.Text = "" Then
msgbox "请选择操作符", vbOKOnly + vbExclamation, "警告"
ComboSign2.SetFocus
Exit Sub
End If
If txtInquire2.Text = "" Then
msgbox "请输入要查询的内容", vbOKOnly + vbExclamation, "警告"
txtInquire2.SetFocus
Exit Sub
End If
'第二个组合段正确,开始添加信息
txtSQL = txtSQL & " " & ComboRelation1.Tag(把组合关系也变成语句来使用,教之分情况,方便!) & " " & ComboFileName2.Tag & ComboSign2.Text & "'" & txtInquire2.Text & "'"
End If
If ComboRelation2.Text <> "" Then '检查第三个组合字段
If ComboFileName3.Text = "" Then
msgbox "请选择字段名", vbOKOnly + vbExclamation, "警告"
ComboFileName3.SetFocus
Exit Sub
End If
If ComboSign3.Text = "" Then
msgbox "请选择操作符", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
If txtInquire3.Text = "" Then
msgbox "请输入要查询的内容", vbOKOnly + vbExclamation, "警告"
txtInquire3.SetFocus
Exit Sub
End If
'第三个组合段正确,开始添加信息
txtSQL = txtSQL & " " & ComboRelation2.Tag & " " & ComboFileName3.Tag & ComboSign3.Text & "'" & txtInquire3.Text & "'"
End If
' txtsql = txtsql & ")" '补充完整"
Print txtSQL
' txtsql = "select * from line_info"
Set mrc = ExecuteSQL(txtSQL, msgText)
查询主要用的SQL语句,这样的查询非常方便,开始我打算分情况,问同学后,发现自己太笨了!所以记录下来,供反思用!