Results 1 to 11 of 11
  1. #1
    revolution9540 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Posts
    18

    Post Filter continuous form by combo box


    I cannot figure out how to filter a continuous form listing values existing in only one table. I want to use a Combo Box to accomplish this. I put custom values into the Combo Box as follows:
    • Dell Laptops
    • HP Minis
    • Surfaces
    • Projectors


    However, I cannot generate the correct code to make this work. Here is what I have so far:
    Code:
    Private Sub Combo30_AfterUpdate()
    If (Me.[Combo30].Value = "Dell Laptops") Then
        Me.Filter = "Brand_Type_Model_Number = '*Dell*'" & Chr(34) & Me.Combo30 & Chr(34)
        Me.FilterOn = True
    End If
    
    
    End Sub
    Basically, I want to filter the form based on items that exist on the Brand/Type/Model_Number field that contain the word Dell, if the value in Combo30 is "Dell Laptops". I get this error when I try to select Dell Laptops from the Combo Box:
    Click image for larger version. 

Name:	Capture.PNG 
Views:	8 
Size:	5.3 KB 
ID:	21521

    Could someone help me out?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Use LIKE operator with wildcards.

    Why do you include the combobox value in the concatenation? Will any data match on "*Dell*Dell Laptops"? This construct requires values to have 'Dell Laptops' in their string.

    Me.Filter = "Brand_Type_Model_Number LIKE '*Dell*'"
    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.

  3. #3
    revolution9540 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Posts
    18
    Quote Originally Posted by June7 View Post
    Use LIKE operator with wildcards.

    Why do you include the combobox value in the concatenation? Will any data match on "*Dell*Dell Laptops"? This construct requires values to have 'Dell Laptops' in their string.

    Me.Filter = "Brand_Type_Model_Number LIKE '*Dell*'"
    Although this got rid of that error message, I am now prompted to enter a parameter. I do not wish to do this, I would just like to filter:
    Click image for larger version. 

Name:	Capture.PNG 
Views:	7 
Size:	2.9 KB 
ID:	21523

    Here is my code now:
    Click image for larger version. 

Name:	Capture.PNG 
Views:	7 
Size:	12.3 KB 
ID:	21524

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Appears Access is not finding Brand_Type_Model_Number field.

    Post the form's RecordSource SQL statement.
    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.

  5. #5
    revolution9540 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Posts
    18
    Record source is simply "Loaner Equipment", which is the name of the table the continuous form is displaying. Brand_Type_Model_Number is a field within that table, so I don't see why Access can't find it.

    I did, however, just make a query to try to troubleshoot this. Now the Record Source is:
    Code:
    SELECT [Loaner Equipment].[Brand/Type/Model Number] FROM [Loaner Equipment];
    I get the exact same message as in post #3.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The field is Brand/Type/Model Number not Brand_Type_Model_Number.

    Me.Filter = "[Brand/Type/Model Number] LIKE '*Dell*'"

    Advise no spaces and special characters/punctuation (underscore is exception) in naming convention. Also, no reserved words as names.
    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.

  7. #7
    revolution9540 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Posts
    18
    Now it works! The reason why I put the underscores is because that's the way the Access autofilled it as I was typing it in, so I assumed that it was an Access convention.

    Even though I have both special characters and spaces in the name, it still works. Does this mean that I will run into problems in the future?

    Thanks for your help!

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    It means will have to remember to enclose the name in [] to define the name.
    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.

  9. #9
    revolution9540 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Posts
    18
    One last question, how do I modify the VBA so I can exclude entries that have the word "Projector" in them? I have a Dell Projector that comes when I filter Dell laptops. I'd like to put in the code a statement that excludes the entry if it contains "Projector" along with "Dell". I am brand new to Access and VBA, so I have a hard time finding this information on Google.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Me.Filter = "[Brand/Type/Model Number] LIKE '*Dell*' AND NOT [Brand/Type/Model Number] LIKE "*Projector*"

    That's the issue with pattern matching. What about other Dell products? Do you want to exclude them?

    Having Brand/Type/Model all in one field is not good design. Discrete data should be in separate fields.
    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.

  11. #11
    revolution9540 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Posts
    18
    Thanks so much, June7!

    This is just one of many tables on the database. This particular table is a smaller one for items that we loan out, most of which are laptops. But there is one projector.

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

Similar Threads

  1. Filter a continuous form using a combo box
    By Chky071 in forum Access
    Replies: 5
    Last Post: 05-04-2015, 08:06 AM
  2. Replies: 3
    Last Post: 09-23-2013, 06:42 AM
  3. Replies: 1
    Last Post: 11-24-2011, 07:45 AM
  4. Filter a Continuous Form
    By michel_annie22 in forum Forms
    Replies: 7
    Last Post: 11-09-2011, 07:34 AM
  5. Continuous Subforms Filter Dependant Combo
    By BigBear in forum Forms
    Replies: 0
    Last Post: 04-19-2009, 08:13 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