ClaraBarton
Registered User.
- Local time
- Today, 02:57
- Joined
- Oct 14, 2019
- Messages
- 789
@MajP I'm struggling with the GetSQL_Filter. Everything was working well until I added in the filter combos. I've tried to work through the function but everytime I edit it I create a mess.
I get this with the below code: (fAmount and fMemo are filter combos)
I want this:
I get this with the below code: (fAmount and fMemo are filter combos)
I want this:
Code:
If Nz(Me.SAmount, 0) <> 0 Then
strAmount = GetSQL_Filter(FAmount, "tblTransactions.Amount = " & Me.SAmount & "" & AndOr)
End If
If Not Trim(SAccount & " ") = "" Then
strAccount = "AccountID = " & Me.SAccount.Value & "" & AndOr
End If
If Not Trim(SMemo & " ") = "" Then
strMemo = GetSQL_Filter(FMemo, "CombMemo = '" & Me.SMemo & "'" & AndOr)
End If
If Not Trim(SName & " ") = "" Then
strName = "FullName = '" & Me.SName & "'" & AndOr
End If
If Not Trim(SDate & " ") = "" Then
strDate = GetDateRange("CkDate", SDate.Value)
End If
Code:
Public Function GetSQL_Filter(TheFilterType As FilterType, ByVal val As String, Optional ByVal val2 As String = "") As String
Dim GSF As String
Select Case TheFilterType
Case flt_Equal
GSF = " = " & val
Case flt_LikeFromBeginning 'Text*
If Left(val, 1) = "'" Then
val = "'*" & MID(val, 2)
Else
val = "'*" & val & "'"
End If
GSF = "Like " & val
Case flt_LikeAnywhere '*test*'
If Left(val, 1) = "'" Then
val = "'*" & MID(val, 2)
val = Left(val, Len(val) - 1) & "*'"
Else
val = "'*" & val & "*'"
End If
GSF = "Like " & val
Case flt_LikeFromEnd 'Text*
If Left(val, 1) = "'" Then
val = Left(val, Len(val) - 1)
val = val & "*'"
Else
val = "'*" & val & "*'"
End If
GSF = "Like " & val
Case flt_GreaterThan
GSF = " > " & val
Case flt_GreaterThanOrEqual
GSF = " >= " & val
Case flt_lessThan
GSF = " < " & val
Case flt_LessThanOrEqual
GSF = " <= " & val
Case flt_Between
If val2 <> "" Then
GSF = "BETWEEN " & val & " AND " & val2
End If
End Select
GetSQL_Filter = GSF
End Function
Attachments
Last edited: