Consulting

Results 1 to 4 of 4

Thread: problem with BuildCriteria and text fields

  1. #1
    VBAX Regular AJS's Avatar
    Joined
    Sep 2004
    Location
    Melbourne
    Posts
    61
    Location

    problem with BuildCriteria and text fields

    Hi,

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

    [VBA]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[/VBA]

    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.

  2. #2
    VBAX Regular AJS's Avatar
    Joined
    Sep 2004
    Location
    Melbourne
    Posts
    61
    Location
    Solved! I'm now using:

    FiltCrit = "Name='Joe'"

  3. #3
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    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)

  4. #4
    VBAX Regular AJS's Avatar
    Joined
    Sep 2004
    Location
    Melbourne
    Posts
    61
    Location
    Thanks, I'll incorporate yr suggestion!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •