Results 1 to 2 of 2
  1. #1
    jcote65 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    1

    Filter on a control


    I have a created a macro that should filter based on a keyword in the control "mot clés" from the table "Banque Jurisprudence Transport". The code is as follows:

    Function FilterKeyword()
    On Error GoTo FilterKeyword_Err

    DoCmd.ApplyFilter "[Banque Jurisprudence Transport]![MOTS CLÉS]", "[contains]", ""


    FilterKeyword_Exit:
    Exit Function

    FilterKeyword_Err:
    MsgBox Error$
    Resume FilterKeyword_Exit

    End Function

    I do get a dialog box with the word contains that lets me enter the keyword I am looking for, however, although the record selector shows the form as being filtered, it is not since I know that there are 5 instances but the record selector shows 72 which is all the records.

    Basically, I am trying to create a macro that would reproduce the following steps:
    - click in the control "mot clés" (French version of keyword)
    - Filter
    - Text filters
    - Contains...
    - I then get a box entitled Custom Filter with the title MOTS CLÉS contains letting me enter the keyword I am looking for

    Any help would be greatly appreciated
    Thank you
    Jeannie

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,958
    I have never used ApplyFilter but don't think you have it right. The syntax and arguments of ApplyFilter are:

    expression.ApplyFilter(FilterName, WhereCondition, ControlName)

    Why have click event call a macro that calls a function? Can put it directly in the Click event. I use only VBA, not macro, code.

    DoCmd.ApplyFilter , "[contains]='" & InputBox("Enter something.") & "'"

    What kind of data is [contains]?

    Problem with this user input is that it is impossible to validate user entry. I would get user input and validate it before running filter.
    Last edited by June7; 01-07-2012 at 02:12 AM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 2
    Last Post: 11-25-2013, 10:56 AM
  2. Replies: 2
    Last Post: 04-17-2012, 12:56 PM
  3. Filter a control on load
    By nick.h in forum Forms
    Replies: 1
    Last Post: 12-01-2011, 02:46 AM
  4. Replies: 1
    Last Post: 11-10-2011, 06:44 PM
  5. Replies: 6
    Last Post: 03-14-2011, 09:37 AM

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