Results 1 to 9 of 9

Macro ApplyFilter Not Working...

  1. #1
    Lobo is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2017
    Posts
    4

    Angry Macro ApplyFilter Not Working...

    Basically I made a search function for a form that split between a form and a query. I added a text box (Text 17) and a button. I then assigned the button to on click preform the event embedded marco, which was set to applyfilter. Where condition = [Username (Forum)] Like "*" & [Forms]![Search]![Text 17] & "*" Or [Forum ID] Like "*" & [Forms]![Search]![Text 17] & "*" Or [Rank] Like "*" & [Forms]![Search]![Text 17] & "*". I have looked over the form location many times to ensure the addresses are correct. Right now my mind is blown as to why it's not working. Basically whenever I click on the command nothing happens, the applyfilter button activates but apart from that nothing happens. I'll provide screen shots of all the code. I will also add that is did work for 10 minutes then stopped for some reason.

    Click image for larger version. 

Name:	ApplyFilter.PNG 
Views:	14 
Size:	41.7 KB 
ID:	27339Click image for larger version. 

Name:	No Result when search preformed.png 
Views:	15 
Size:	134.5 KB 
ID:	27340Click image for larger version. 

Name:	Property Sheet For Button.PNG 
Views:	14 
Size:	33.9 KB 
ID:	27341Click image for larger version. 

Name:	Where Condition.PNG 
Views:	14 
Size:	39.9 KB 
ID:	27342Click image for larger version. 

Name:	Property Sheet For Text Box.PNG 
Views:	14 
Size:	39.1 KB 
ID:	27343

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    7,738
    try the filter without all the ORs.

  3. #3
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,047
    I think that your [text17] will return a text value and therefor needs to be given extra quotes to ensure it's read as a string.

    Have you tried setting up a string
    Dim criteriastring as string
    Criteriastring = [username etc....
    Debug.print criteriastring
    Stop

    Then run the program and copy the criteria string and pasting in the sql window of a new query.

    That way you'll see what's wrong and be able to edit it



    Sent from my iPhone using Tapatalk

  4. #4
    Lobo is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2017
    Posts
    4
    So extra quotes around the "*" or [Text 17]? I would try and set up a string but I've never used the visual basic side of access before.

  5. #5
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Being unfamiliar with macros I could not get it working - however, this is what you would have if you change the OnClick to an Event Procedure:

    Code:
     
    Me.Filter = "[Username (Forum)] Like ""*" & Forms!Search![Text17] & "*"" Or [Forum ID] Like ""*" & Forms!Search![Text17] & "*"" Or [Rank] Like ""*" & Forms!Search![Text17] & "*"""
    Me.FilterOn = True
    Me.Requery

  6. #6
    Lobo is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2017
    Posts
    4
    Thanks it works. Though I don't quite undestand why it didn't work through the embedded macro that is basically doing the same.

  7. #7
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    It is all in the quotes! Here is a good article on it: http://allenbrowne.com/casu-17.html

  8. #8
    Lobo is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2017
    Posts
    4
    When ever I tried to add quotes access stated the where condition was invalid .

  9. #9
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Me too! That is why I gave up trying to get the macro working, far easier to get what you want in VBA. Time to get your feet wet with VBA anyway!

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

Similar Threads

  1. FilterByForm Macro then ApplyFilter
    By dscottf in forum Macros
    Replies: 1
    Last Post: 10-28-2015, 04:58 AM
  2. Replies: 15
    Last Post: 10-02-2015, 12:07 PM
  3. Replies: 2
    Last Post: 06-17-2015, 12:20 PM
  4. Replies: 1
    Last Post: 01-21-2015, 02:02 PM
  5. Macro to VBA not working?
    By mgio in forum Programming
    Replies: 5
    Last Post: 07-16-2014, 02:01 PM

Posting Permissions

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