Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8642391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:45:52+00:00 2026-06-12T11:45:52+00:00

I have a main form, frm_Main, and it has a subform in it, subform_Child.

  • 0

I have a main form, frm_Main, and it has a subform in it, subform_Child. When the main form is displayed the subform is shown as well, it’s just blank because there’s no data in it (which is perfectly fine). When the user clicks a button on the main form the code builds a SQL string that contains a WHERE clause based upon what the user has entered in a text box. So far so good, I’ve done this before. Now the part that I cannot figure out (because I haven’t done it before) is populating that subform using the SQL just created! Building the SQL string is no problem, I just don’t know Access VBA well enough to know what code to use to update the subform from the main form and have it display the recordset after the query runs.

Edit: It’s my understanding that using a QueryDef isn’t a recommended method, correct?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:45:53+00:00Added an answer on June 12, 2026 at 11:45 am

    Here’s what I did as it seems to be the only way to do it.

    1) Built a query named “zqry_PlaceHolder”. In my case this is the data set that is being used (only the WHERE will change). I did add a WHERE clause in this (WHERE dbo_project.projectid = “_”) but only so it would return nothing so as not to delay the displaying of the main form.

    2) In the subform set the Source Object to the query I just built, “Query.zqry_PlaceHolder”. This is required.

    3) When the user clicks the button on the main form the VBA code is run. It creates the WHERE clause in the string variable sWhereFilter and then adds it to the SQL string:

    'Build SQL string
    sSQL = Empty  'Ensure string is empty
    sSQL = "SELECT Proj_Locs.ProjectID, dbo_PROJECTS.PROJECTID, Proj_Locs.Location, Master_Scans.FileName, Proj_Locs.Title, dbo_PROJECTS.TITLE" & vbCrLf
    sSQL = sSQL & "FROM (tbl_Project_Locations AS Proj_Locs" & vbCrLf
    sSQL = sSQL & "    LEFT JOIN dbo_PROJECT AS dbo_PROJECTS ON Proj_Locs.ProjectID = dbo_PROJECTS.PROJECTID)" & vbCrLf
    sSQL = sSQL & "    LEFT JOIN tblMasterScans AS Master_Scans ON Proj_Locs.ProjectID = Master_Scans.Project" & vbCrLf
    sSQL = sSQL & sWhereFilter
    sSQL = sSQL & "ORDER BY Proj_Locs.ProjectID ASC, dbo_PROJECTS.PROJECTID ASC;"
    

    Then I throw up a “Please wait” form to let the user know things are processing and set the RecordSource of the subform to the built SQL string:

    DoCmd.OpenForm "frm_PleaseWait", acNormal
    DoCmd.Hourglass True
    DoCmd.RepaintObject acForm, "frm_PleaseWait"  'Needed to show everything in the form immediately, otherwise there's a delay
    Me.subform_Results.Form.RecordSource = sSQL  'This updates the subform AND executes it, refreshing the results
    Beep  'Let user know processing completed
    Me.txt_RecordsReturned = Me.subform_Results.Form.Recordset.RecordCount  'Let user know how many records were returned with their query (if any)
    

    This works and it does not change the placeholder query “zqry_PlaceHolder”.

    I hope this helps others as it wasn’t as intuitive to me. If there is another/better method I’m all for learning something new!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main Form. There is a linklabel. If i click on it,
I have main form and some other forms, that can be shown by controls,
I have a main form with a tab control, and each tab has a
I have a main form that has 5 MDI children. When the main form
I have my main form which has a NotifyIcon attached for balloon tips. I
I have a main form that users fill out, and at the bottom there
In my current application I have a main form: frmMain with a statusstrip and
I have a Main form.I want to launch another form from it and launch
I have a main form, and a floating child form that is non-modal. The
I have a main form and non-modal autocomplete form. How can I prevent the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.