Results 1 to 3 of 3
  1. #1
    vector39 is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    May 2017
    Posts
    76

    Search as you type VBA

    Hello everyone



    Basically what I would like to do is replicate Allen Browne's brilliant example (found here http://allenbrowne.com/appfindasutype.html) of a form filtering records as you type or by selecting different options based on a combo box. I followed this example exactly, however I realized, the limitations section indicates why this example isn't feasible. I have a datasheet that I wish to filter using a search bar and a combo box. But one of the columns is a yes/no data type. Does anyone have any insight or guidance on how I can search for records using a query in split form? Thank you.

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    yes no can be queried by using -1 for yes, 0 for no (-1 is the check mark, 0 is an unchecked value).
    so if the search works for numeric value fields you should be able to adapt the code to deal with a yes/no field.

    Probably in this section:

    Code:
        'Unfilter if there is no text to find, or no control to filter. Otherwise, filter.
        If (strText = vbNullString) Or (strField = vbNullString) Then
            frm.FilterOn = False
        Else
            'this section works for text fields only
            'I would tend to look up the data type from the source table and build this statement accordingly BUT
            'you could do something here for a specific field like:
            if strfield = "YES NO FIELD NAME HERE" Then
                frm.filter = strfield & " = " & if(strtext = "Yes", -1, 0)
            else
                 frm.Filter = strField & " Like """ & IIf(mbcStartOfField, vbNullString, mstrcWildcardChar) & strText & mstrcWildcardChar & """"
            endif
            frm.FilterOn = True
        End If

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    or do it the other way round

    your form recordsource would be something like

    SELECT fld1, fld2,booleanfield, format(booleanfield,"yes/No") as txtBooleanfied.....
    FROM....

    in your form, display booleanfield, but search on txtbooleanfield

    or just display the txtbooleanfield - just depends on what the user can do with the data

    Alternatively
    you can also use the eval function

    strfilter =strfilter & "eval([" & strfield & "] = " & me.searchfld & ") AND "

    or universally

    strfilter =strfilter & "eval([" & strfield & "] Like *" & me.searchfld & "*) AND "

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Search as i type
    By Manuel Ferreira in forum Access
    Replies: 2
    Last Post: 05-24-2016, 06:23 AM
  2. Replies: 8
    Last Post: 11-20-2015, 10:08 AM
  3. Search as you type
    By Farnarkle in forum Programming
    Replies: 3
    Last Post: 11-17-2014, 06:03 AM
  4. Search as you type
    By CaptainKen in forum Programming
    Replies: 19
    Last Post: 04-25-2012, 12:55 PM
  5. search as you type in combo box
    By pratim09 in forum Forms
    Replies: 3
    Last Post: 08-05-2011, 07:46 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums