[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Set recordsource of a subform using code

Posted on 2011-05-03
3
Medium Priority
?
394 Views
Last Modified: 2012-06-27
I have a bunch of queries. Which one will be executed depends on the date range the user enters in a couple of textboxes on a form.  How would I modify the code below to set a SUBFORM's recordsource? The code below was used on another one of my projects where I set the FORM's recordsource.  This time, I need to set the SUBFORM's recordsource.  The subform's name is SUBFORM1. Thank you.

QueryNameForReport = QueryName

If (IsNull(ANYDATA)) Then GoTo NoDataMessage
   DoCmd.OpenForm "Form1"
   Set frm = Forms("Form1")
   With frm
  .RecordSource = QueryName   <------ (QueryName is a variable that is set to the name of the
                                                                 appropriate query based upon which date range a
                                                                 user selects)
0
Comment
Question by:dbfromnewjersey
3 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 500 total points
ID: 35516739


If (IsNull(ANYDATA)) Then GoTo NoDataMessage
   DoCmd.OpenForm "Form1"
   Set frm = Forms("Form1")
   With frm
      .SUBFORM1.Form.RecordSource = QueryName

mx
0
 
LVL 49

Assisted Solution

by:Dale Fye
Dale Fye earned 500 total points
ID: 35516748

After opening form1, you could just use:

Forms("Form1").subFormControlName.Form.RecordSource = "QueryName"

where "subFormControlName" is the name of the control, when viewed on Form1, not the "ControlSource" of the subform.
0
 

Author Comment

by:dbfromnewjersey
ID: 35688588
Thank you.
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

834 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