Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2005
    Posts
    5

    Filter data on a form from another control on the same form

    Not sure its the exact description I want but here goes.



    I have 2 tables setup like so:

    Table 1 (Locations):

    Location_ID (Primary Key)
    Location_Name
    Location_Addr_1
    Location_Addr_2
    etc etc etc

    Basically an address file with a location ID.

    Table 2 (Resources):

    Location_ID (Primary Key)
    Resource_ID
    Resource_Description

    Essentially a list of resources with the location ID for each one.

    Now, I have my main form displaying primarily the information from table one.

    What I now need to do is add a listbox displaying the resource information from Table 2; this needs to be filtered so that it only shows the resource information relevant to the particular location being displayed.

    Ive tried adding a listbox, and setting its Control Source to Location_ID, but it still shows ALL of the resources from the entire Table 2, instead of just for the location that is being displayed.

    A sub-form does work in a fashion, but I have the feeling a sub-form is a little overkill for my needs. I dont need to edit any of the data, just browse it.

    I did try to setup a query, but I cant find a way to reference Locations.Location_ID from the main form as a criteria for the query.

    Can anybody help please ?

    :?:

  2. #2
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    One way to do it is change the "Row Source" of listbox to filter the record based on the "Location_ID" from the main form (table Location).

    The "Row Source" would look something like this.

    Row Source = SELECT Location_ID, Resource_ID, Resource_Description FROM Resources WHERE Location_ID = Forms![MainFormName]![Location_IDNameFromMainForm]

  3. #3
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    lfpm got it right. Also, you should be able to refer to the location ID's control on the form directly as Me.Controlname, so the rowsource could look something like this:
    Code:
    "SELECT [Resource_ID], [Resource_Description] FROM [MyTable2] WHERE [Location_ID] =" & Me.MyLocationIDControlName

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

Similar Threads

  1. Form Based Query/Filter
    By Micon in forum Access
    Replies: 0
    Last Post: 11-07-2008, 09:25 AM
  2. Linked control in form
    By Zipster1967 in forum Forms
    Replies: 0
    Last Post: 04-14-2007, 01:40 PM
  3. Most reliable way to edit form data in VBA...?
    By samalter in forum Programming
    Replies: 0
    Last Post: 06-23-2006, 12:39 PM
  4. Run report or sub form during data entry
    By wasim_sono in forum Programming
    Replies: 0
    Last Post: 03-09-2006, 05:40 AM
  5. Form/Subform - Update control help!
    By f_ali in forum Forms
    Replies: 2
    Last Post: 02-26-2006, 12:59 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