标题: 请帮解决SQI的问题 [打印本页] 作者: kill718 时间: 2008-3-10 19:23 标题: 请帮解决SQI的问题 Function GetSQL(strTable As String) As String
On Error GoTo Err_GetSQL
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSQL As String, strSQLWhere As String
Dim strOperation As String, i As Integer
Dim intCount As Integer
strSQL = "SELECT * FROM tblSearch "
strSQL = strSQL & "WHERE (Field Is Not Null) And (KeyWord Is Not Null)"
Set conn = CurrentProject.Connection
rs.Open strSQL, conn, adOpenKeyset, adLockOptimistic
intCount = rs.RecordCount
If intCount = 0 Then
GetSQL = "SELECT * FROM [" & strTable & "];"
Else
For i = 1 To intCount
If rs("Operation1") = conAND Then
strOperation = " And "
ElseIf rs("Operation1") = conOR Then
strOperation = " Or "
End If
If intCount = 1 Then
strSQLWhere = GetSQLWhere(rs("Field"), rs("KeyWord"), rs("Operation2"))
Else
If i = 1 Then
strSQLWhere = strSQLWhere & GetSQLWhere(rs("Field"), rs("KeyWord"), rs("Operation2"))
Else
strSQLWhere = strSQLWhere & strOperation & GetSQLWhere(rs("Field"), rs("KeyWord"), rs("Operation2"))
End If
End If
rs.MoveNext
Next
GetSQL = "SELECT * FROM [" & strTable & "] WHERE " & strSQLWhere & ";"
End If
rs.Close
Set rs = Nothing
Set conn = Nothing