I have an OpenForm with a where statement which throws up an error because the form i'm trying to open uses a query which has two fields from different tables sharing the same name.
Let me explain how this relates. I've create a Project Manager program.
I have a table for Projects (TBProjects) with fields 'ProjectID', 'ProjectName' and 'StatusID'(plus others).
Another table for the Tasks (TBTasks). The Tasks table has fields for 'TaskID', 'ProjectID', 'StartDate', 'EndDate' and 'StatusID'(plus others).
Then another table for Status (TBStatus) with the 'StatusID' indicating 1 for Not Started, 2 for In Progress and 3 for Completed.
I want to open a form that shows only those records in TBTasks that are for a specific Project(via ProjectID) and are (A) Not Started AND (B) Not Started and Over Due AND (C) Started but Over Due.
To do this the all three fields in TBTasks mentioned above must be used, 'StartDate', 'EndDate' and 'Status'.
Therefore my OpenForm looks quite complex
The Error Message I get is:
"The Specific field '[StatusID]' could refer to more than one table in the FROM clause of your SQL satatement."
The Query SQL is:
Without the where statment the OpenForm works perfectly and I get no error message in regard to the SQL statement.
I've tried using [TBTasks.StatusI D] instead of [StatusID] in the where statement but then i get a different error message
"You've enterted a expresion that has no value"
Is there something within the SQL statement that I have to do or do i need to change the syntax of the where statement?
Usually i would keep most of the criteria within the query itself but in this case I need 3 different types of criteria (A) Not Started,(B) Not Started and Over Due and (C) Started but Over Due. I could create 3 separate queries which will work using the conditions in either A, B and C. So perhaps is there a way of combining the records in 3 different queries onto 1 form ?
Thanks.
Let me explain how this relates. I've create a Project Manager program.
I have a table for Projects (TBProjects) with fields 'ProjectID', 'ProjectName' and 'StatusID'(plus others).
Another table for the Tasks (TBTasks). The Tasks table has fields for 'TaskID', 'ProjectID', 'StartDate', 'EndDate' and 'StatusID'(plus others).
Then another table for Status (TBStatus) with the 'StatusID' indicating 1 for Not Started, 2 for In Progress and 3 for Completed.
I want to open a form that shows only those records in TBTasks that are for a specific Project(via ProjectID) and are (A) Not Started AND (B) Not Started and Over Due AND (C) Started but Over Due.
To do this the all three fields in TBTasks mentioned above must be used, 'StartDate', 'EndDate' and 'Status'.
Therefore my OpenForm looks quite complex
Code:
DoCmd.OpenForm "FRMTasksByProjectOverDue", , ,_ "([ProjectID] = " & ChosenProjectOverDue & "And [StatusID] = 1 And [StartDate] <= #" & Now & "# And [Enddate] <= #" & Now & "#)_ AND ([ProjectID] = " & ChosenProjectOverDue & "And [StatusID] = 1 And [StartDate] <= #" & Now & "# And [Enddate] >= #" & Now & "#)_ AND ([ProjectID] = " & ChosenProjectOverDue & "And [StatusID] = 2 And [Enddate] <= #" & Now & "#)"
"The Specific field '[StatusID]' could refer to more than one table in the FROM clause of your SQL satatement."
The Query SQL is:
Code:
SELECT DISTINCT TBProjects.ProjectID, TBProjects.ProjectName,_ TBProjects.StatusID, TBProjects.StaffID, TBTasks.TaskID,_ TBTasks.Title, TBTasks.StaffID, TBTasks.StartDate, TBTasks.EndDate,_ TBTasks.StatusID, TBProjects.ProjectStartDate, TBProjects.ProjectEnddate FROM TBProjects INNER JOIN TBTasks ON TBProjects.ProjectID = TBTasks.ProjectID;
I've tried using [TBTasks.StatusI D] instead of [StatusID] in the where statement but then i get a different error message
"You've enterted a expresion that has no value"
Is there something within the SQL statement that I have to do or do i need to change the syntax of the where statement?
Usually i would keep most of the criteria within the query itself but in this case I need 3 different types of criteria (A) Not Started,(B) Not Started and Over Due and (C) Started but Over Due. I could create 3 separate queries which will work using the conditions in either A, B and C. So perhaps is there a way of combining the records in 3 different queries onto 1 form ?
Thanks.
Comment