I'm trying to assign a recordsource to a subform.
I have the following variable defined:
Dim QueryName as string
Based on IF THEN ELSE logic, I assign the applicable query name to the QueryName variable.
A snippet of it looks something like this:
If txtYear = 2005 then
QueryName = "qry2005"
elseif txtYear = 2006 then
QueryName = "qry2006"
I then try to assign QueryName to the RecordSource of a subform on a form. It looks like this:
Forms("frmForm2").subform1.Form.RecordSource = "QueryName"
When I try to run the code, which is executed by clicking a command button on a separate form (named Form1), I get the following message:
'The record source 'QueryName' specified on this form or report does not exist
So, what I'm trying to do is use a form with a command button and a textbox on it. The user enters a year and clicks the command button. The command button should open up Form2 with subform1 on it. subform1 should contain the output of the applicable query.
What am I doing wrong?