Results 1 to 3 of 3
  1. #1
    sra2786 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Location
    Cincinnati, OH
    Posts
    38

    How to display data from query/SQL in a subform

    I have a Combo Box to select a material. I have a Command Button that I want to use the Combo Box material to select data from a table and then display those records in a subform. Maybe a subform is not the best object to use to display the data. I want the data to displayed on the same form as the Combo Box and Command Button. I cannot figure out how to do this. Can someone send me some sample code?
    Thanks.

  2. #2
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    You don't need the button if the user making a combo selection would be the point at which you'd generate the subform records. If there has to be some other interaction with the form that must happen first, then maybe a button. The combo/button would be on the main form. The main form would need a subform control. When you drag the subform control onto the main form's detail section, Access will prompt you to select the form that should go in there if you have "Use Control Wizards" selected in the Ribbon, which means you should design the subform query first, then the subform. When prompted, refer to the subform you have created. You can also base the subform on a table if the db design allows it, but I try to use queries as they're easily modified. If more than one table is involved in the subform records, you have to use a query anyway, not to mention that if you're going to use a form control for criteria input, it's far easier using a query.

    The subform wizard will give a name to the subform control that (usually) is the same name as the subform you put in it. That's not a real good thing; I suggest you rename it according to the naming convention you have (I hope) adopted. The query criteria for the proper field should refer to the form control as in
    Code:
    Forms!frmYourFormName.YourControlName
    Either the combo box AfterUpdate event (alternatively your button click event) should requery the sub form, which will automatically run the query.
    Not enough info in your post to be able to say much more than that. At least you have a start - create the query, subform and add it to the main form. I don't see from your information that you need to worry about parent/child linking between main and subform. Perhaps you should research Access subform creation to bring yourself up to speed.

    Access does have what's called a split form, which is an easier route for those without the knowledge required for subforms, but they certainly do have their limitations. IMHO, you should avoid them if you can.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I don't think a sub form would be required.

    Sounds like:
    1) a form with a query as the record source,
    2) the form in continuous forms mode,
    3) an unbound combo box in the form header and
    4) the controls laid out in a horizontal line. (kinda like a datasheet)

    The combo box after update event would set the form filter and a button (in the header) to remove the filter.

    My mantra: KISS - keep it simple Steve......

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

Similar Threads

  1. Replies: 10
    Last Post: 11-29-2016, 10:20 AM
  2. Display data in a subform based on Search
    By natonstan in forum Queries
    Replies: 1
    Last Post: 12-04-2014, 09:17 AM
  3. Subform data won't display
    By paulajo in forum Forms
    Replies: 3
    Last Post: 07-25-2012, 04:13 PM
  4. Subform won't display data
    By bobn3faw in forum Forms
    Replies: 1
    Last Post: 02-10-2011, 09:55 PM
  5. Replies: 2
    Last Post: 06-17-2010, 04:15 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