Results 1 to 3 of 3
  1. #1
    Scandiaman is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Oct 2012
    Location
    Poulsbo, WA
    Posts
    6

    FIltering forms using an unbound field


    Hello all, and thanks in advance for any help you can provide. I’ll try to make this as short as possible, but I think that’s impossible

    I am a fairly novice Access/MS Visual Basic programmer and have what I imagine, is a very simple problem that I just cannot figure out. I have spent many hours trying different methods to achieve what I want to do, but with no success. Hopefully one of you genius’s can point me in the right direction. Among other objects, here’s what I have and what I am trying to do. For reference, attached is a PDF file with images of my database’s design. Tables and forms are in bold, and fields are underlined:

    pg1.pdf pg2.pdf pg3.pdf pg4.pdf

    I have a form named ‘OrdersF’ which is linked to two tables, ‘OrdersT’ and ‘CustomersT’. The ‘OrdersF’ form stores everything in the ‘OrderT’ table. The ‘Customer’ field on the ‘OrdersF’ form gets its value (lookup) from the from the ‘Customer’ field in the ‘Customers’ table and stores it in the ‘OrdersT’ table’s ‘Customer’ field as a text object, NOT as a number from the ‘CustomersT’ table’s key field ‘ID’.

    On the ‘OrdersF’ form I have another unbound Combo Box control named ‘FilterForCustomer’ that looks up all customers from the ‘Customers’ table and sets its value to whichever customer is selected. In the ‘AfterUpdate’ event in this Combo Box’s properties, I have added the following code:
    DoCmd.ApplyFilter , Customer = FilterForCustomer
    The function that I wish to happen is that, after selecting a specific customer in the ‘FilterForCustomer’ combo box, the value in that field is immediately used (that’s why the code is in the AfterUpdate event) to filter/display just the records in which the ‘Customer’ field’s values equals the customer that is displayed in the ‘FilterForCustomer’ field.
    The ‘OrdersT’ table will eventually have thousands of entries in it and scrolling through tons of records to find one with the correct customer in it so that you could select ‘Filter by Selection’ would take too long, and selecting ‘Filter for:’ requires you to type in the name exactly correct. I like the way that the Combo Box works, where you just start typing and it tries to display the closes match from what you have typed so far. This method is quick and avoids mistakes.

    The problem that I am having is that after the code is run, the filter doesn’t respond correctly and filters out all records. In the attached screen shots, you can see what I mean. I have tried using macros, tried using full syntax in object names, and a number of other experiments, but am still stuck. Can any of you help me get this resolved? I would really appreciate any advice.

    Thanks,
    John Wells
    Last edited by Scandiaman; 10-28-2012 at 03:27 PM. Reason: misplacement of attachments

  2. #2
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    You are not using the Applyfilter method correctly. The second parameter has to be a string expression which is the SQL equivalent to a where clause, but without the where. Try changing Customer = FilterForCustomer to "Customer = " & FilterForCustomer.

    John

  3. #3
    Scandiaman is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Oct 2012
    Location
    Poulsbo, WA
    Posts
    6
    WOW! You fixed it! See, I knew it was easy, I just didn't understand the syntax. I've got a couple of real thick books but I just couldn't find what I was looking for.

    I owe you one... or two or three. Let me know if I can help you in any other way.
    Thanks again,

    John

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

Similar Threads

  1. Filtering Forms
    By Lupson2011 in forum Forms
    Replies: 1
    Last Post: 02-07-2012, 04:48 PM
  2. Filtering forms by date
    By rwest in forum Forms
    Replies: 1
    Last Post: 01-03-2012, 11:23 AM
  3. Filtering Forms
    By Iggsy in forum Forms
    Replies: 6
    Last Post: 11-23-2011, 01:01 AM
  4. Unbound form for data filtering
    By alliandrina in forum Access
    Replies: 7
    Last Post: 05-21-2011, 05:19 PM
  5. Combo Box Filtering between Forms
    By andrew_ww in forum Access
    Replies: 3
    Last Post: 12-30-2009, 11:06 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
  •  
Other Forums: Microsoft Office Forums