Results 1 to 3 of 3

Thread: ApplyFilter syntax

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004
    Location
    Surrey, UK
    Posts
    163

    ApplyFilter syntax

    Hi,

    I am trying to filter my displayed records by their project name.

    Under a button click I have this code:

    VB Code:
    1. DoCmd.ApplyFilter , "[ProjectName] Like '*' & '1st floor' & '*'"

    and it filters the records to only show ones with '1st floor' in the projectname


    BUT I want to be able to change the '1st floor' parameter so I did this...(created a textbox "txtSearch" to type in my variable)

    VB Code:
    1. DoCmd.ApplyFilter , "[ProjectName] Like '*' & [txtSearch].Value & '*'"

    but this comes up with an "Enter Parameter Value" message box for txtSearch.Value

    So I tried this....

    VB Code:
    1. Dim tmp As String
    2.     tmp = "*" & txtSearch.Value & "*"
    3.     DoCmd.ApplyFilter , [ProjectName] Like tmp


    and it does the same as above except asks for tmp.


    How can I write this correctly to find the value I type in the text box on the form??

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004
    Location
    Surrey, UK
    Posts
    163

    Re: ApplyFilter syntax

    doh


    done it :O)

    VB Code:
    1. DoCmd.ApplyFilter , "[ProjectName] Like '*" & Me.txtSearch & "*'"

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004
    Location
    Surrey, UK
    Posts
    163

    Re: ApplyFilter syntax

    I've now added my new code to my form and it works fine.


    However, in my finished database that form is a subform on my main menu.

    And according to microsoft knowledge it accepts that you cannot apply a filter to a subform.

    http://support.microsoft.com/default...b;en-us;209482

    Can anyone think of a way round this?

    Or another way to program it completely??

Posting Permissions

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



Click Here to Expand Forum to Full Width