MS Access 2013 - Load a Query into the record source of the subform using VBA Code

Posted on 2014-08-14
Last Modified: 2014-08-14
I have a main and subform and wish to load a query into the subform record source using VBA but I don't know the syntax to do this.

The main form name is:  F-100-00 StartUpMain
The subform name is:  F-100-01 CFR_Pivot-All Records
The query name is: Q-100-01 CFR_Pivot-All records

I want to use VBA code to make the record source of the subform  (F-100-01 CFR_Pivot-All Records)
"Q-100-01 CFR_Pivot-All records" when the code is executed.

Question: Using the information listed above provide me with the correct syntax so that I can add this code statement to my VBA Sub process

Thanks for your assistance.
Question by:Lou Dufresne
    LVL 56

    Accepted Solution

    If the code is in the main form:

     Me![<name of subform control>].Form.Recordsource = "Q-100-01 CFR_Pivot-All records"

    "<name of subform control>" is the name of the control on the main form.   It may or may NOT be the same as the name of the subform as you see it in the database.   Click on the subform control, then look at the property sheet.   You want the name, not the sourceobject.

    LVL 1

    Author Closing Comment

    by:Lou Dufresne
    Thanks Jim. This is a big help to me


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
    I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now