Results 1 to 4 of 4
  1. #1
    Steven19 is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2020
    Location
    London
    Posts
    110

    Filter a Query dependent Form

    In my attached database I am trying to filter the form frmUKAccountsOpen, which is filtered through query QryUKAccountsOpen

    The issue Im having is that no matter what method I use, I have tried a few, my textbox, txtNameFilter keeps asking for a parameter value.

    The code I am using is borrowed from an online source and is:

    Private Sub txtNameFilter_KeyUp(KeyCode As Integer, Shift As Integer)


    On Error GoTo errHandler


    Dim filterText As String


    'Apply or update filter based on user input.
    If Len(txtNameFilter.Text) > 0 Then
    filterText = txtNameFilter.Text
    Me.Form.Filter = "[QryUKAccountsOpen]![CompanyName] LIKE '*" & filterText & "*'"
    Me.FilterOn = True
    'Retain filter text in search box after refresh.
    txtNameFilter.Text = filterText
    txtNameFilter.SelStart = Len(txtNameFilter.Text)
    Else
    ' Remove filter.
    Me.Filter = ""
    Me.FilterOn = False
    txtNameFilter.SetFocus
    End If


    Exit Sub


    errHandler:


    MsgBox Err.Number & " - " & Err.Description, vbOKOnly, "Error ..."




    End Sub

    I tried Me.Form.Filter = "[frmUKAccountsOpen]![CompanyName] LIKE '*" & filterText & "*'" but had the same issue.

    This is just a part of a bigger database, but just need to make this fiddly thing work but cant get my head around it.

    Ideas on just this issue please?

    Regards
    Attached Files Attached Files

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Try

    Me.Form.Filter = "[CompanyName] LIKE '*" & filterText & "*'"

    Personally I'd use the change event, but I can't think of a reason why.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Steven19 is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jun 2020
    Location
    London
    Posts
    110
    Excellent solution. It worked fine.

    Thank you


  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 1
    Last Post: 09-13-2017, 12:29 PM
  2. Replies: 4
    Last Post: 02-13-2016, 06:00 PM
  3. Replies: 1
    Last Post: 03-27-2012, 01:30 PM
  4. Update Query Dependent on the month
    By hawkins in forum Queries
    Replies: 3
    Last Post: 07-12-2011, 08:54 AM
  5. Creating a query with a self-dependent field
    By lottrup in forum Queries
    Replies: 0
    Last Post: 06-20-2011, 04:30 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