Dim rstTemp As New ADODB.Recordset
Dim strDftFltName As String
Dim strWhere As String
rstTemp.Open "select ffiltername from tblZstmFilterSave where fform='" & rstrFrmName & "' and fuser='" & gt_strUserName & "' and fisdefault=true ", CodeProject.Connection, adOpenStatic, adLockReadOnly
If rstTemp.RecordCount > 0 Then
strDftFltName = rstTemp.Fields("ffiltername")
Else
strDftFltName = ""
End If
rstTemp.Close
'strDftFltName = Nz(DLookup("ffiltername", "tblZstmFilterSave", "fform='" & Me.Name & "' and fuser='" & gt_strUserName & "' and fisdefault=true "))
CodeDb.Execute "delete * from tblZstmFilter"
CodeDb.Execute "insert into tblZstmFilter (FId, FSeq, Fform, FName, FRela, FField, FCaption, FLogic, FValue, FType) select FId, FSeq, fform, FName, FRela, FField, FCaption, FLogic, FValue, FType from tblZstmFilterSaveDetail where ffiltername='" & strDftFltName & "' and fform='" & rstrFrmName & "' and fuser='" & gt_strUserName & "'"
Dim varName As Variant
Dim strTmp As String
Dim i, j As Integer
Dim strCtlL, strValue, strLogic, pPara As String
Dim strSql As String
strSql = "select * from tblZstmFilter where fform='" & rstrFrmName & "' order by fseq"
rstTemp.Open strSql, CodeProject.Connection, adOpenStatic, adLockReadOnly
pPara = ""
Do While Not rstTemp.EOF
i = i + 1
If i = 1 Then
strCtlL = " "
Else
strCtlL = IIf(rstTemp("FRela") = "或", " or ", " and ")
End If
strValue = rstTemp("FValue")
strLogic = Trim(rstTemp("FLogic"))
If strLogic = "$" Then
strValue = "*" & strValue & "*"
strLogic = " LIKE "
End If
If strLogic = "=" Then
strValue = strValue & "*"
strLogic = " like "
End If
pPara = pPara & strCtlL & rstTemp("FField")
Select Case rstTemp("FType")
Case "Text", "Memo"
If strLogic = "IN" Then
varName = Split(strValue, ",")
strTmp = ""
For j = 0 To UBound(varName)
If j = 0 Then
strTmp = strTmp & " like '" & varName(j) & "*' "
Else
strTmp = strTmp & " or " & rstTemp("FField") & " like '" & varName(j) & "*' "
End If
Next
'strTmp = Left(strTmp, Len(strTmp) - 1)
strValue = strTmp
strLogic = " IN "
pPara = pPara & strTmp
Else
pPara = pPara & strLogic & " '" & strValue & "'"
End If
Case "Longint", "Int", "Double", "Currency", "Boolean", "Autoid"
If strLogic = "IN" Then
varName = Split(strValue, ",")
strTmp = ""
For j = 0 To UBound(varName)
strTmp = strTmp & varName(j) & ","
Next
strTmp = left(strTmp, Len(strTmp) - 1)
strValue = strTmp
strLogic = " IN "
pPara = pPara & strLogic & "(" & strValue & ")"
Else
pPara = pPara & strLogic & strValue
End If
pPara = pPara & strLogic & " '" & strValue & "' "
Else
pPara = pPara & strLogic & " '" & Date & "' "
End If
End If
End Select
rstTemp.MoveNext
Loop
If pPara = "" Then pPara = " true "
'CurrentProject.Application.Forms(rstrFrmName).Tag = pPara
gt_GetDefaultFilter = pPara
End Function 作者: Henry D. Sy 时间: 2012-5-12 14:12
坐个沙发