PDA

View Full Version : problem with BuildCriteria and text fields



AJS
11-30-2004, 11:09 PM
Hi,

I am having some difficulty getting the following code fragment to work:

Private Sub Combo10_Change()

Dim FormFilter As String
Dim FiltField As String
Dim FiltCrit As String

If Form_Table1.Combo10.Value = "Joe" Then

FiltField = "Name"
FiltCrit = "Name=Joe"

FormFilter = BuildCriteria(FiltField, dbText, FiltCrit)

Else

FormFilter = ""

End If

Form_Table1.Filter = FormFilter
Form_Table1.FilterOn = True

End Sub

Basically, when this runs it brings up a dialog box that is captioned "Joe", rather than automatically filtering for names = Joe. I use a comparable syntax for boolean and date filters, and they seem to work fine, but for some reason this doesn't work smoothly for text fields.

Thanks, Aaron.

AJS
11-30-2004, 11:40 PM
Solved! I'm now using:

FiltCrit = "Name='Joe'"

geekgirlau
12-05-2004, 06:29 PM
Just be careful if using this method on a text field that might contain ' in the text (such as O'Brien). You might want to try

FiltCrit = "Name=""Joe"""

Or if you're like me and get confused with too many quotes,

FiltCrit = "Name=" & Chr(34) & "Joe" & Chr(34)

AJS
12-07-2004, 02:48 PM
Thanks, I'll incorporate yr suggestion!