So much fun when have limited time and get these errors. I create an SQL in the Report-Open event. It's a simple Select query with FROM two tables INNER joined and then three other tables in LEFT JOIN. I keep getting the error that "field RespOrg could refer to more than on table in FROM clause." I know this is true and so I fixed it by prefixing with variable representing the table name and when I do Debug.Print the "TableName.RespOrg" is spelled out!! I specify the table name using a string variable strJT (JobTableYYYY) since in opening the report, the use specifies a year and each table has the year at end of table, e.g. JobDetail2013, JobDetail2014,... So, prior to the SQL create lines, I assign the variable strJT to the actual table name with the correct year at end.
[strSQL = "SELECT " & strJT & ".FICSYr, " & strJT & ".RespOrg, [RespOrgs].[RespOrgName], " & strJT & ".Job, JobDesc, ContactNew, PM_GS, Sjob, SjobDesc, UCACurrent, " _
& "SjobDateEffective, SjobDateLaborExpire, " _
& "SjobDateODCExpire, SjobScope, ReasonNewSjob, ReasonCloseSjob " _
& "FROM ((((" & strJT & " INNER JOIN " & strJST & " ON " & strJT & ".Job = " & strJST & ".Job) LEFT JOIN RespOrgs ON " & strJT & ".RespOrg = RespOrgs.RespOrg) " _
& "LEFT JOIN Contacts ON " & strJT & ".ContactID = Contacts.ContactID) LEFT JOIN PMs ON " & strJT & ".PM_GS_ID = PMS.PM_Id) " _
& "WHERE " & strJT & ".Job = '" & strJob & "'" _
& "ORDER BY RespOrg, Job, Sjob;"
Debug.Print strSQL
Me.RecordSource = strSQL][/code]
The field RespOrg is a field in strJT (JobDetail2015) for example. RespOrg is also a field in table RespOrgs in FROM clause. Debug.Print shows "Select ... JobDetail2015.RespOrg, ..."
Thanks for considering this question. Searching this forum did not help in this case.
Jeff
[strSQL = "SELECT " & strJT & ".FICSYr, " & strJT & ".RespOrg, [RespOrgs].[RespOrgName], " & strJT & ".Job, JobDesc, ContactNew, PM_GS, Sjob, SjobDesc, UCACurrent, " _
& "SjobDateEffective, SjobDateLaborExpire, " _
& "SjobDateODCExpire, SjobScope, ReasonNewSjob, ReasonCloseSjob " _
& "FROM ((((" & strJT & " INNER JOIN " & strJST & " ON " & strJT & ".Job = " & strJST & ".Job) LEFT JOIN RespOrgs ON " & strJT & ".RespOrg = RespOrgs.RespOrg) " _
& "LEFT JOIN Contacts ON " & strJT & ".ContactID = Contacts.ContactID) LEFT JOIN PMs ON " & strJT & ".PM_GS_ID = PMS.PM_Id) " _
& "WHERE " & strJT & ".Job = '" & strJob & "'" _
& "ORDER BY RespOrg, Job, Sjob;"
Debug.Print strSQL
Me.RecordSource = strSQL][/code]
The field RespOrg is a field in strJT (JobDetail2015) for example. RespOrg is also a field in table RespOrgs in FROM clause. Debug.Print shows "Select ... JobDetail2015.RespOrg, ..."
Thanks for considering this question. Searching this forum did not help in this case.
Jeff