Link to home
Start Free TrialLog in
Avatar of Jenkins
JenkinsFlag for United States of America

asked on

Set recordsource of a subform using code

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)
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jenkins

ASKER

Thank you.