Hi There -
I have a parent form called [/b]Companies[/b] populated by a Companies table and a subform called People_Subform populated by the People table and linked to the parent form via the People_ID primary key.
I'm using a toggle button to toggle the recordsource for these forms between their native tables and a query, with parameters supplied by text boxes in the header of the Companies form.
If I execute the query from the query window, I get the expected results, but when I try to use the query as a record source for my forms, I get this message:
Run-time error '3079':The specified field 'Company' could refer to more than one table listed in the FROM clause of your SQL statement.
Here's the code behind my toggle button:
And here's the SQL statement from my query:
The textboxes used for search criteria are in the header area of the parent form Companies and are named First_Name_Search and Last_Name_Search. They are unbound.
If I remove the field People.Company from my query, the query returns the expected result in the query window, but it won't populate my subform; it does, however, return the Company to the parent form Companies. When I leave the [People].[Company] field as part of my query, the company field on my Companies parent form returns #Name?, and all employees at that company show in my subform.
What's going on? Suggestions?
Thanks for you help!
Tom
I have a parent form called [/b]Companies[/b] populated by a Companies table and a subform called People_Subform populated by the People table and linked to the parent form via the People_ID primary key.
I'm using a toggle button to toggle the recordsource for these forms between their native tables and a query, with parameters supplied by text boxes in the header of the Companies form.
If I execute the query from the query window, I get the expected results, but when I try to use the query as a record source for my forms, I get this message:
Run-time error '3079':The specified field 'Company' could refer to more than one table listed in the FROM clause of your SQL statement.
Here's the code behind my toggle button:
Code:
Private Sub Toggle_Filter_Companies_AfterUpdate()
If Toggle_Filter_Companies.Value = -1 Then
Toggle_Filter_Companies.Caption = "Remove Filter"
Me.RecordSource = "Companies_Filter_Query"
Me.People.Form.RecordSource = "Companies_Filter_Query"
Me.Requery
Else
Toggle_Filter_Companies.Caption = "Apply Filter"
Me.RecordSource = "Companies"
Me.People.Form.RecordSource = "People"
End If
Me.Requery
End Sub
And here's the SQL statement from my query:
Code:
SELECT Companies.Company_ID, Companies.Company, Companies.Address, Companies.Address2, Companies.City, Companies.State_Province, Companies.Zip_Postal_Code, Companies.Address_Type, Companies.Use_For_Billing, Companies.Primary, Companies.Website, People.FirstName, People.MiddleName, People.LastName, People.Status, People.Company, People.Job_Title, People.Incomplete
FROM Companies INNER JOIN People ON Companies.Company_ID = People.Company
WHERE (((People.FirstName) Like '*' & [Forms]![Companies]![First_Name_Search] & '*') AND ((People.LastName) Like '*' & [Forms]![Companies]![Last_Name_Search] & '*'));
The textboxes used for search criteria are in the header area of the parent form Companies and are named First_Name_Search and Last_Name_Search. They are unbound.
If I remove the field People.Company from my query, the query returns the expected result in the query window, but it won't populate my subform; it does, however, return the Company to the parent form Companies. When I leave the [People].[Company] field as part of my query, the company field on my Companies parent form returns #Name?, and all employees at that company show in my subform.
What's going on? Suggestions?
Thanks for you help!
Tom